5 Replies Latest reply: Jul 4, 2007 12:59 PM by 796440 RSS

    Date Format

    807605
      Hi,

      I am trying to update a record in Database. its a PostgreSql Database. the table contains a field with data type "timestamp with timezone"...the records already there have format "2006-06-01 09:55:12.837656+02".

      I tried to update DB by creating a date like
      Date date = new Date(System.currentTimeMillis());
      and sending update to DB, but it update the field like "2007-07-04 00:00:00+02".

      can anybody tell me how can format the date in the format specified above and update DB.

      I am using preparedstatement are using its methods setDate().
        • 1. Re: Date Format
          807605
          The java.sql.Date is intended to represent a date without time information. You should better use java.sql.Timestamp instead (and the corresponding PreparedStatement's setTimestamp() method, of course.)
          • 2. Re: Date Format
            807605
            Hmmm.... I don't see anything in java.sql.Timestamp or java.sql.* that can allow you to set a specific timezone. How is that handled?
            • 3. Re: Date Format
              796440
              Hmmm.... I don't see anything in java.sql.Timestamp
              or java.sql.* that can allow you to set a specific
              timezone. How is that handled?
              java.util.Date and its subclasses in java.sql are TZ-agnostic. They don't hold or need any TZ information.

              If I create a Date object in California at the same instant that someone in Tokyo creates a Date object, those two Dates will have the same millis-since-epoch long. His will not be 1000 * 60 * 60 * 16 larger than mne.


              TZ only comes into play when viewing or parsing dates, and then you use DateFormat.
              • 4. Re: Date Format
                807605
                I don't know if it's standard SQL (and who cares?) but I think there are
                examples of SQL date/timestamp column types that include an explicit time zone:

                http://www.postgresql.org/docs/8.0/static/datatype-datetime.html
                • 5. Re: Date Format
                  796440
                  I don't know if it's standard SQL (and who cares?)
                  but I think there are
                  examples of SQL date/timestamp column types that
                  include an explicit time zone:

                  http://www.postgresql.org/docs/8.0/static/datatype-dat
                  etime.html
                  Interesting, and slighly icky and frightening.

                  Although I can see where it might occasionally be useful to explicitly specify "local time."