• 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: Displaying Local Time on a Web Client
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Displaying Local Time on a Web Client


  • Subject: Re: Displaying Local Time on a Web Client
  • From: "Mr. Pierre Frisch" <email@hidden>
  • Date: Tue, 31 Mar 2009 15:48:41 -0700

Beware that SimpleDateFormat is not reentrant so stashing it somewhere may not be safe. And please don't use NSTimestampFormatter if you are using local times it is deprecated and does not work correctly in particular with daylight saving time and such.

Pierre
--
Pierre Frisch
email@hidden


On Mar 31, 2009, at 9:56, Chuck Hill wrote:


On Mar 31, 2009, at 9:20 AM, David Avendasora wrote:

Okay I know this must be easy, but I just can't seem to get it to work.

I just want to display the time a particular page was displayed.

My component has this:

CurrentTimestamp : WOString {
 value = currentTimestamp;
 dateformat ="%m/%d/%y %H:%M";
}

When currentTimestamp returns a new NSTimestamp I get GMT, which is what I expected.

But when I return an NSTimestamp create like so:

GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(new NSTimestamp());
NSTimestamp timestamp = new NSTimestamp(calendar.getTimeInMillis(),
		                        TimeZone.getTimeZone("America/Chicago"));
return timestamp;

I still get GMT.

What fundamental thing am I missing or doing wrong?


Gosh, where does does one start? Oh, my. Best sit down, this will take a while. What, just the date? OK then... ;-)

Use the formatter, not the timestamp to control the time zone it is shown in. And don't use the dateFormat and numberFormat bindings. Bad. Or at least don't hard code them. Otherwise you have much to change when you need to change the format. Better to use the formatter binding and an instance of java.util.format (SimpleDateFormat or NSTimestampFormatter). And stash it in your session for a bit of optimization. But I digress.

That should do it, assuming the client and server are in the same time zone. If not, you will have to determine the user's time zone and use that to set the time zone of the formatter. Yet another good reason to stash it in the session.


Chuck


-- Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects







_______________________________________________ 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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: Displaying Local Time on a Web Client
      • From: Chuck Hill <email@hidden>
References: 
 >Displaying Local Time on a Web Client (From: David Avendasora <email@hidden>)
 >Re: Displaying Local Time on a Web Client (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: modeling problem
  • Next by Date: Re: Displaying Local Time on a Web Client
  • Previous by thread: Re: Displaying Local Time on a Web Client
  • Next by thread: Re: Displaying Local Time on a Web Client
  • Index(es):
    • Date
    • Thread