Re: NSTimestamp problem
Re: NSTimestamp problem
- Subject: Re: NSTimestamp problem
- From: Ray Kiddy <email@hidden>
- Date: Sun, 15 Jun 2008 11:47:55 -0700
On Jun 15, 2008, at 5:05 AM, Simon McLean wrote:
time zone. Europe / London is currently in BST which is 1 hour
ahead of GMT.
i think if you also print out GregorianCalendar.HOUR_OF_DAY you'll
find it's = 11, not 12, because it's using GMT.
depending on what you are trying to achieve you may find it easier
to work everything at GMT rather than local timezone, then convert
to local (if required) when displaying to user. You can do so by
sticking this in your application constructor:
NSTimeZone.setDefaultTimeZone(NSTimeZone.getGMT());
Simon
I would add and imperitive to this statement. Please. Avoid much
pain. When you are storing timestamps, fetching timestamps, comparing
timestamps, or doing anything with timestamps that uses them as
_data_, use GMT. When you are displaying timestamps, use a formatter
and display to a user-supplied, session-tracked time zone.
Please do this. The mailing list will thank you. We really do not
want to see anyone else go through that pain.
Keep to MVC design here and things will be much better. If you think
about it, a timestamp that includes a time zone is a bad idea. A
timestamp represents some time, abstractly, that something happened
somewhere in our universe. When you display that timestamp to a user,
the user is at a place and they are looking at the timestamp at some
other time. And so at that point, one can use the time zone
(geography) of the person (not the geographical location of your
server, which the user does not care about) and DST-ness (from human-
created arbitrary policies) to determine how to display the timestamp.
Keep the "model" part of the timestamp separate from the "view" part
of the timestamp and you will end up much, much happier.
cheers - ray
On 15 Jun 2008, at 12:55, Gino Pacitti wrote:
Does anyone have a link to solution to hour of day being incorrect?
NSTimeZone tz = NSTimeZone.timeZoneWithName("Europe/
London", true);
java.util.GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(new NSTimestamp());
int year = calendar.get(GregorianCalendar.YEAR);
int dayOfMonth = calendar.get(GregorianCalendar.DAY_OF_MONTH);
int month = calendar.get(GregorianCalendar.MONTH);
int hour = calendar.get(GregorianCalendar.HOUR_OF_DAY);
int minute = calendar.get(GregorianCalendar.MINUTE);
int second = calendar.get(GregorianCalendar.SECOND);
NSTimestamp correctedDate = new NSTimestamp(year, ++month,
dayOfMonth, hour, minute, second, tz);
Current time
2008-06-15 12:51:15 Etc/GMT
System.out.println("Time Stamp Date" + correctedDate);
Time reported
2008-06-15 11:51:15 Etc/GMT
Why do I loose the hour?
WO 5.3.* OSX 10.4.11 Java 1.5
Any help appreciated..
Gino
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40ganymede.org
This email sent to email@hidden
_______________________________________________
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