• 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
Re: NSTimestamp problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimestamp problem


  • Subject: Re: NSTimestamp problem
  • From: Simon McLean <email@hidden>
  • Date: Sun, 15 Jun 2008 13:05:22 +0100

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



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:
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
  • Follow-Ups:
    • Re: NSTimestamp problem
      • From: Ray Kiddy <email@hidden>
References: 
 >NSTimestamp problem (From: Gino Pacitti <email@hidden>)

  • Prev by Date: NSTimestamp problem
  • Next by Date: Re: WebObjects + iPhone SDK
  • Previous by thread: NSTimestamp problem
  • Next by thread: Re: NSTimestamp problem
  • Index(es):
    • Date
    • Thread