Java Programming Tutorial – 36 – Time Class

Home/Programming Video Tutorials/Java Video Tutorials/Java Programming Tutorial – 36 – Time Class

Java Programming Tutorial – 36 – Time Class

FavoriteLoadingAdd to favorites

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

Java468x60
By | 2017-06-10T01:31:38+00:00 June 10th, 2017|Java Video Tutorials|50 Comments

50 Comments

  1. Flore Loriz June 10, 2017 at 1:35 am - Reply

    Hey, I have a question. Is it a good idea to name your object variables as $tuna instead of tunaObject? Let’s say the name for all your object variables begins with $ and you know if you see $, that is an object?. Is that a good idea (why/why not)? Thank You!

  2. Kulanx Dorane June 10, 2017 at 1:36 am - Reply

    %02d and %O2d are sooooooooo similar…

  3. uh loco June 10, 2017 at 1:37 am - Reply

    I have no idea why he uses String.format, what is that supposed to mean? I know that method returns a string which is the one in between brackets, it is the "format" word that buggs me, he never declared that

  4. Suhail Pappu June 10, 2017 at 1:38 am - Reply

    i did without using the private and just used as int hour ……… and the code compiled well then wts the use of using private? plz explain.

  5. DARKNIGHT 》 June 10, 2017 at 1:38 am - Reply

    "wow would you look at that" 😂epic.

  6. Kareem Hamed June 10, 2017 at 1:39 am - Reply

    2:01 check it out…hahahahahahahaha priceless

  7. omer abbas June 10, 2017 at 1:44 am - Reply

    this thing is so complicated.He was good at the beginning but now he is going fast iam last.Anyone knows a good utuber?

  8. Evgeni Kuzmov June 10, 2017 at 1:47 am - Reply

    it’s printed out 13:13:13 wtf

  9. Official IamUya June 10, 2017 at 1:47 am - Reply

    toMilitary has an x on it. How did you automatically make it as a string

  10. FunReviews June 10, 2017 at 1:49 am - Reply

    If someone doesn’t understand the %02d stuff, visit this helpful link: http://stackoverflow.com/questions/3377688/what-do-these-symbolic-strings-mean-02d-01d

  11. hagu June 10, 2017 at 1:52 am - Reply

    class MainClass {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    tuna Obj=new tuna();
    System.out.println(Obj.Tom());
    Obj.SetTime(6,7,8);
    System.out.println(Obj.Tom());

    }

    }
    public class tuna {
    private int hour;
    private int min;
    private int sec;
    public void SetTime(int h,int m,int s){
    hour=((h>=0 && h<24) ? h : 0);
    min=((m>=0 && m<60) ? m : 0);
    sec=((s>=0 && s<60) ? s : 0);
    }
    public String Tom(){
    return String.format("%O2d:%O2d:%O2d", hour,min,sec);
    }

    }
    here is my code where ‘s the problem?
    compiler show some error.
    like:Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ‘O’
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.lang.String.format(Unknown Source)
    at tuna.Tom(tuna.java:12)
    at MainClass.main(MainClass.java:7)

  12. WinkyEgg June 10, 2017 at 1:54 am - Reply

    6:28 Why it should give us all zeros by default? Looks like the the variables have not been initialized yet.. Thank you.

  13. Carlos Acosta June 10, 2017 at 1:55 am - Reply

    I keep getting this error, Idk why I’m using eclipse too
    Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier ‘%d’
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.lang.String.format(Unknown Source)
    at C2.Military(C2.java:12)
    at tutos.main(tutos.java:5)

  14. SUPERFASTH June 10, 2017 at 1:59 am - Reply

    whats the defference between public static void and public static?

  15. Preston Galloway June 10, 2017 at 2:00 am - Reply

    turns on computer gets on youtube "okay im going to watch programming videos for a few minutes" 3 hours later looks up at clock "dang it"

  16. tohin sarker June 10, 2017 at 2:00 am - Reply

    What is the link between setTime() Method and toMilitary() Method? there are to different method , why toMIllitary method getting value from setTime() method?? i ididnt understand, anyoune can help me??

  17. chuchuchuchia June 10, 2017 at 2:02 am - Reply

    Apples and tuna got me fawked all the way up, Java is confusing :/

  18. omer abbas June 10, 2017 at 2:03 am - Reply

    it is not working i did the same thing

  19. Robert Reimann June 10, 2017 at 2:04 am - Reply

    Why the fuck don’t you just use constructor for this shit?? omfg xD

  20. Marc Opie June 10, 2017 at 2:06 am - Reply

    I gen an error: "The method format(String, Object[]) in the type String is not applicable for the arguments (String, int)

    String.format seems to want a String and an Object as arguments, not a String and an integer.

  21. shamma AlKaabi June 10, 2017 at 2:06 am - Reply

    String.format is like using printf right? I mean there is no difference between them ? – -"

  22. Robbrt B June 10, 2017 at 2:07 am - Reply

    Instead of printing 00 00 00 and 13 27 06 it prints 00 00 00 twice. help

  23. Ben Michalowicz June 10, 2017 at 2:08 am - Reply

    I followed the tutorial at every possible interval, but here is what pops up in the display box upon completion:

    Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ‘O’
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.lang.String.format(Unknown Source)
    at TimeClass2.toMilitary(TimeClass2.java:17)
    at TimeClass.main(TimeClass.java:6)

    Does anyone have any suggestions?

  24. Evgeni Kuzmov June 10, 2017 at 2:09 am - Reply

    i had the green bar too

  25. Bruh June 10, 2017 at 2:09 am - Reply

    hey did he not use static on the line public void setTime(int h, int m, int s){

  26. RulerL0rd June 10, 2017 at 2:09 am - Reply

    You are a good programmer but your voice is lazy. I have to finish your tutorials and fast (probably until the end of the year).

  27. Ahmad Habib June 10, 2017 at 2:10 am - Reply

    what is String.format( )
    is used for..?
    anyone..? bucky…?

  28. Ramy Tawfik June 10, 2017 at 2:11 am - Reply

    what are the conditions of writing the word "static"

  29. mallika saha June 10, 2017 at 2:11 am - Reply

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method format(String, Object[]) in the type String is not applicable for the arguments (String, int, int, int)

    i got this error can anyone help me to solve it. The code was written exactly like the video

  30. Sherine Ahmed June 10, 2017 at 2:12 am - Reply

    why this condition hour=((hour>0 && hour<24)?h:0); gives zero and put hour=((hour>=0 && hour<24)?h:0);(equal sign) make it pop right !

  31. The Spankles June 10, 2017 at 2:13 am - Reply

    it says that format is wrong? PLEASE HELP

  32. Braskit8 June 10, 2017 at 2:15 am - Reply

    "Military time" = regular time, yanke time is just annoying : P

  33. Mervin Lee June 10, 2017 at 2:15 am - Reply

    In line 7,8 and 9 in the tuna class, is this similar to a if statement because you didn’t write a if hour = ? thanks!

  34. Ramy Tawfik June 10, 2017 at 2:17 am - Reply

    why do we have to return the integers as strings ?

  35. adi5151 June 10, 2017 at 2:18 am - Reply

    For everyone that gets error Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ‘O’
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.lang.String.format(Unknown Source)
    at tuna.toMilitary(tuna.java:42)
    at apples.main(apples.java:10)

    in string.format use 0 (number) instead of O (letter) and check the rest of "%02d […]" you need to have exactly the same code

  36. Haffiz Bilal June 10, 2017 at 2:18 am - Reply

    sir i want to come in us after graduation and i live in pakistan and my cousin live in us since 20 years he said that visa are not available for pakistani in these days sir plz tell me if i want to come in us and work as JAVA DEVELOPER any thing works for me as java developer in us plz answer

  37. harry wood June 10, 2017 at 2:19 am - Reply

    Thought it was a tutorial to build a time machine using Java. Disappointed, disliked, commented with hatred, left.

  38. Tinky Winky June 10, 2017 at 2:19 am - Reply

    In my country time is displayed the same way as in "military time". Btw how did no one comment about what he said at 2:02 I was laughing my ass off when he said that.

  39. Subhadarshi Samal June 10, 2017 at 2:20 am - Reply

    Can you explain why haven’t you declare SetTime(int h, int m, int s) as static ?? So far you have been declaring all methods with public static void methodname().

  40. Stringboy Music Production June 10, 2017 at 2:21 am - Reply

    I’m gettin an error in toMilitary method: The method format(String, Object[]) in the type String is not applicable for the arguments (String, int, int, int)

  41. Deansidious FitnessChannel June 10, 2017 at 2:21 am - Reply

    Hi guys, I just wanna ask when I accidentally put hour for both minute and second under the public void setTime method; the values popped up were 06:00:00 for 13, 21, 6. Any explanation on why is the value 6 under the hour column but not the value 13?

    public class biceps {
    private int hour;
    private int minute;
    private int second;

    public void setTime (int h, int m, int s){
    hour = ((h>=0 && h<24) ? h : 0);
    {mistake i made; supposed to be minute} > hour = ((m>=0 && m<60) ? m : 0);
    {mistake i made; supposed to be second} > hour = ((s>=0 && s<60) ? s : 0);
    }

    public String toMilitary() {
    return String.format("%02d:%02d:%02d", hour, minute, second);
    }
    }

  42. Ashish Mehrotra June 10, 2017 at 2:24 am - Reply

    just write sysout in eclipse hit cntl+enter automatically System.out.println() pops up..

  43. AmazingCraft0210 June 10, 2017 at 2:24 am - Reply

    What does String.format do I don’t understand can someone help? and can someone help me with return String.format("%02d:%02d:%02d", hour, minute, second);

  44. Kaysar777 June 10, 2017 at 2:25 am - Reply

    %02d means two digits, not two decimal places. 😀

  45. Shritej Chavan June 10, 2017 at 2:27 am - Reply

    Did he say "After Effects" ?? Wow i love this guy>

  46. Nidhi Prasad June 10, 2017 at 2:27 am - Reply

    Why we have a return type as String . We could have accepted the h,m and s in a void method and print them with prinntf("%02d:%02d:%02d",hm,m,s). wouldnt this do the same job. So whats the purpose of a string return type and String.format? plz plz help. Thanks so much!

  47. Abhishek Malakar June 10, 2017 at 2:28 am - Reply

    please help anyone, It’s showing up an error like this
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
    The method format(String, Object[]) in the type String is not applicable for the arguments (String, String, int)

    at apples.main(apples.java:4)
    I typed exactly :-
    return String.format("%02d:%02d:%02d",hour,min,sec);

  48. Muntaseer Rahman June 10, 2017 at 2:29 am - Reply

    shouldnt the condition be h>=0 && h<=24? I mean hours can have 24…

  49. Prabin Ojha June 10, 2017 at 2:30 am - Reply

    why isn’t the method made static?

  50. ManOFSteel June 10, 2017 at 2:31 am - Reply

    "kind ,but not kind enough"

Leave A Comment

*