4 Replies Latest reply: Jul 22, 2009 5:01 AM by PhHein RSS

    Date

    807588
      Hai...
      I have a small program


      package date;


      import java.util.Date;
      import java.text.ParseException;
      import java.text.SimpleDateFormat;


      public class dateConverting {
      public static void main(String art[]) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
      long cDate = 0;
      Date d = null;
      try {
      // d = sdf.parse("1951-07-22 07:10:20");
      d = sdf.parse("1970-01-01 5:30:00");
      // d = sdf.parse("2009-07-22 07:10:20");
      } catch (ParseException e) {
      e.printStackTrace();
      }
      cDate = d.getTime();
      System.out.println("d.getTime() ----------[?? why ??]---------> " + d.getTime());
      System.out.println("d.getMinutes() ----------[]---------> " + d.getMinutes());
      System.out.println("d.getDate() ----------[]---------> " + d.getDate());
      System.out.println("d.getTimezoneOffset() ----------[]---------> " + d.getTimezoneOffset());
      }
      }

      Here, at the time 1970-01-01 5:30:00 ,d.getTime() shows value zero. If we give a time before 1970-01-01 5:30:00 (for eg. 1951-07-22 07:10:20), it shows negative value and if it is after.. it shows positive value. What does it mean? why 1970-01-01 5:30:00 shows zero value? Can anyone help me... thanks for your replies in advance.

        • 1. Re: Date
          masijade
          Because 0 is 1970-01-01 00:00:00.000 UTC and your timezone is, seemingly +5:30.

          You do know that Date is simply a count of the milliseconds since the epoch (which is the time listed above), right?
          • 2. Re: Date
            PhHein
            From the Date API:
            Date
            public Date(long date)
            > Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
            > Parameters:
            > date - the milliseconds since January 1, 1970, 00:00:00 GMT.
            > See Also:
            > System.currentTimeMillis()
            • 3. Re: Date
              YoungWinston
              masijade. wrote:
              Because 0 is 1970-01-01 00:00:00.000 UTC and your timezone is, seemingly +5:30.
              I wonder what part of India OP is doing this from? :-)

              Winston
              • 4. Re: Date
                Herko_ter_Horst
                Why? India (all of it) has it's own timezone which is 5.5 hours ahead of GMT.