Date and Time problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KusoYumi
    New Member
    • Mar 2008
    • 11

    Date and Time problem

    Hello, im facing date and time problem. I want get a time in Date Type, with this format HH:mm:SS
    i try to get new Date(), then format it as String. Then i use substring to get the time. Then i parse it as Date Type, and want to save it in database(databa se has a field called start_time, which is Date Type)
    After i do this transaction and check with database, database show "1970-01-01 17:12:00".....C an anyone help me on that?Thanks in advanced
  • radhikams
    New Member
    • Jan 2008
    • 49

    #2
    Originally posted by KusoYumi
    Hello, im facing date and time problem. I want get a time in Date Type, with this format HH:mm:SS
    i try to get new Date(), then format it as String. Then i use substring to get the time. Then i parse it as Date Type, and want to save it in database(databa se has a field called start_time, which is Date Type)
    After i do this transaction and check with database, database show "1970-01-01 17:12:00".....C an anyone help me on that?Thanks in advanced
    Can you tell me which class you used.. I mean the Date class or the Calendar class of the util package..Also can you a bit more clearer of the problem

    Comment

    • Navdip
      New Member
      • Mar 2008
      • 22

      #3
      Originally posted by radhikams
      Can you tell me which class you used.. I mean the Date class or the Calendar class of the util package..Also can you a bit more clearer of the problem
      Calendar c = new GregorianCalend ar(1985,SEPTEMB ER, 05);
      String s = String.format(" Date of birth Birthday: %1$tm %1$te,%1$tY", c);
      System.out.prin tln("Date of Bith is:- "+s);

      u can change the date format like above code. u have to import following class and packages:- util.GregorianC alendar & util.Calendar.* ;

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Navdip
        Calendar c = new GregorianCalend ar(1985,SEPTEMB ER, 05);
        String s = String.format(" Date of birth Birthday: %1$tm %1$te,%1$tY", c);
        System.out.prin tln("Date of Bith is:- "+s);

        u can change the date format like above code. u have to import following class and packages:- util.GregorianC alendar & util.Calendar.* ;
        Please don't post spoon feeding code; I told you this before; you shouldn't do it.
        Read the forum guidelines by pressing the 'Help' link near the top of this page.
        Also use the code tags when you do have to post a code fragment, don't use
        the bold tags. Also post correct code, not incorrect code; it is confusing at
        least to the OP. Consider this a warning. You stand the risk of a ban.

        kind regards,

        Jos

        Comment

        • KusoYumi
          New Member
          • Mar 2008
          • 11

          #5
          Originally posted by radhikams
          Can you tell me which class you used.. I mean the Date class or the Calendar class of the util package..Also can you a bit more clearer of the problem
          Im using java.util.Date, i convert the Time from String(HH:mm:SS format, value is 17:12:19) to Date, then it become "1970-01-01 17:12:00". Can i know why it become 1970-01-01?

          Comment

          • KusoYumi
            New Member
            • Mar 2008
            • 11

            #6
            Originally posted by Navdip
            Calendar c = new GregorianCalend ar(1985,SEPTEMB ER, 05);
            String s = String.format(" Date of birth Birthday: %1$tm %1$te,%1$tY", c);
            System.out.prin tln("Date of Bith is:- "+s);

            u can change the date format like above code. u have to import following class and packages:- util.GregorianC alendar & util.Calendar.* ;
            Firstly im thank that you provide an example for me, i have tried, but it show Date, which not Time, any way, i appreciated u guys willing help :) further explaination on my problem, i have replied radhikams..
            From the output, i can know that tm is month, te is day and tY is year, but may i know is it use tY, tm and te as default? can use other naming?and why need %1?
            im newbie in java, pls forgive if i have ask stupid question.Thanks =)

            Comment

            Working...