Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format timestamp according to a given timezone #137

Closed
badtant opened this issue Dec 5, 2012 · 2 comments
Closed

Format timestamp according to a given timezone #137

badtant opened this issue Dec 5, 2012 · 2 comments

Comments

@badtant
Copy link

badtant commented Dec 5, 2012

Hi!

I have a timestamp that I use to print a time useing this code:
Globalize.format(new Date(timestamp), "T");

This will result in different times according to witch timezone the client is in. Is there any easy way to provide a timezone (in my case +01) to Globalize and get dates and times corrected to this timezone?

Thanks

@omerA
Copy link

omerA commented Jan 30, 2013

Sorry for barging in, but you can write a simple function that does that.
Just make a new date and subtract you're current timezone offset from UTC.
Here's a simple example (CoffeeScript / Javascript):

get_new_date_in_local_time: (date) ->
date = new Date date
new Date date.getTime() + (date.getTimezoneOffset() * 60 * 1000)

getNewDateInLocalTime = function(date){
date = new Date(date);
return new Date(date.getTime() + (date.getTimezoneOffset() * 60 * 1000);
}

You can just put it inside globalize.js and use it.

Hope it helps.

@rxaviers
Copy link
Member

rxaviers commented Jun 3, 2014

Closing in favor of #202, which will define how timezone will be addressed in new Globalize 1.x rewrite.

@rxaviers rxaviers closed this as completed Jun 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants