0 Replies Latest reply: Aug 8, 2013 2:02 AM by sabre150 Branched from an earlier discussion. RSS

    Re: Error in the conversion of a date in ms for october before 1996

    sabre150

      939520 wrote:

       

      I searched Google for SimpleDateFormat and Timezone, and found this article:

      http://eyalsch.wordpress.com/2009/05/29/sdf

      Looks like you might consider using GMT time for all date/time calculations as follows, which

      will return the same value everywhere in the world:

        SimpleDateFormat sdf = new SimpleDateFormat('dd-MM-yyyy');

        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

       

      Note: I always store GMT time in the database for all projects, then convert it to a person's locale as needed for display.

       

       

      The OP's code assumes that the string dates are in his default timezone. His code will convert these dates to java.util.Date objects which store all dates as the number of milliseconds since 1/1/1970 00:00:00 UTC ( the epoch ). There is only ever any need to specify the timezone with SimpleDateFormat if the date string is is not in the default time zone. The site the OP is using as a reference also assumes that the string versions are in the default time zone so the comparison should be valid.

       

      P.S. Strictly one should use UTC and not the outdated GMT.