• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTimestampFormatter adjusts TZ for display, SimpleDateFormat doesn't?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTimestampFormatter adjusts TZ for display, SimpleDateFormat doesn't?


  • Subject: NSTimestampFormatter adjusts TZ for display, SimpleDateFormat doesn't?
  • From: Paul Hoadley <email@hidden>
  • Date: Wed, 15 Apr 2009 19:07:26 +0930

Hello,

Using WO 5.4.3.  Here's yet another NSTimestamp/NSTimestampFormatter/SimpleDateFormat thread...  :-)

Heeding the deprecation warning for NSTimestampFormatter, I've been trying to use SimpleDateFormat in its place.  I'm doing the following:

1.  PostgreSQL is set to GMT.
2.  Application() contains this:

// Set the default TZ for NSTimestamps to GMT
NSTimeZone.setDefaultTimeZone(NSTimeZone.getGMT());
// Set the default TZ for Java
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

3.  Column C in table T is of type "TIMESTAMP WITHOUT TIME ZONE".
4.  I'm inserting a creation timestamp into C using 'new NSTimestamp'.  I can confirm that the current time in GMT is inserted into T.
5.  A user preference system allows users to nominate a local timezone if they prefer not to see the dates as GMT.
6.  In the Session I store a SimpleDateFormat constructed like this:

SimpleDateFormat sdf = new SimpleDateFormat("...some format string...");
sdf.setTimeZone(userLocalTZ);

Where userLocalTZ is an NSTimeZone constructed from the save preference.
7.  When I try to use the SimpleDateFormatter, it doesn't adjust the construction timestamp when binding it to a wo:string formatter.  Here's some debugging output:

SurveyInstanceList.timestampFormat: ((NSTimeZone) result.getTimeZone()).secondsFromGMT()) = 34200

This is the TimeZone from the SimpleDateFormat: it's the correct offset from GMT.

SurveyInstanceList.timestampFormat: constructionDate().timeZone() = Etc/GMT (GMT) offset 0

This is the TimeZone from the timestamp.  It's in GMT.

SurveyInstanceList.timestampFormat: result.format(constructionDate())) = 15/04/2009 08:34:41

This is the result of the format: the timestamp is not adjusted, and appears exactly as it appears in the database.

8.  If I pull the same TimeZone out of the SimpleDateFormat and use it to create an NSTimestampFormatter, it works:

nsf.setDefaultFormatTimeZone((NSTimeZone)result.getTimeZone());

Using nsf.format adjusts the time to the user's nominated local timezone as expected.

What am I doing wrong with SimpleDateFormat?


-- 
Paul.

w  http://logicsquad.net/
h  http://paul.hoadley.name/


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTimestampFormatter adjusts TZ for display, SimpleDateFormat doesn't?
      • From: Andrew Lindesay <email@hidden>
  • Prev by Date: Re: migrations in framework
  • Next by Date: Re: NSTimestampFormatter adjusts TZ for display, SimpleDateFormat doesn't?
  • Previous by thread: Re: storing NSTimestamp values as GMT, displaying as (client) local?
  • Next by thread: Re: NSTimestampFormatter adjusts TZ for display, SimpleDateFormat doesn't?
  • Index(es):
    • Date
    • Thread