• 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: Lachlan Deck <email@hidden>
  • Date: Mon, 16 Jun 2008 07:55:42 +1000

On 15/06/2008, at 9:55 PM, 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);

TimeZone tz = TimeZone.getTimeZone( "Europe/London" );
Calendar cal = Calendar.getInstance( tz ); // cal instanceof GregorianCalendar == true
// no need to setTime, it's already set to current time
// no need to get values. Use the calendar itself to adjust the month
cal.add( Calendar.MONTH, 1 );


TimeZone tz = TimeZone.getTimeZone( "Europe/London" );
Calendar cal = Calendar.getInstance( tz ); // cal instanceof GregorianCalendar == true
// no need to setTime, it's already set to current time
// no need to get values. Use the calendar itself to adjust the month
cal.add( Calendar.MONTH, 1 );
SimpleDateFormat fm = new SimpleDateFormat("ddMMyyyy hh:mm:ss");
fm.setTimeZone( tz );
System.out.println( "New date:" + fm.format( cal.getTime() ) );


NSTimestamp correctedGMTDate = new NSTimestamp( cal.getTime() );

with regards,
--

Lachlan Deck

_______________________________________________
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


References: 
 >NSTimestamp problem (From: Gino Pacitti <email@hidden>)

  • Prev by Date: Re: n00b Q:Getting a database entity count
  • Next by Date: Re: ReportMill can't find Framework?
  • Previous by thread: Re: NSTimestamp problem
  • Next by thread: n00b Q:Getting a database entity count
  • Index(es):
    • Date
    • Thread