0

I want to convert unix timestamp to time for a particular timezone.

say for example unix time stamp is - 1446960600 I want to convert this timestamp to America/Los Angeles ?

1
  • your question is no clear ? can you tell which format actually you need Commented Nov 8, 2015 at 1:38

2 Answers 2

3

You can convert a unix timestamp integer into a Javascript date like this

var date = new Date(1446960600 * 1000);

Unix timestamps are in the UTC timezone, but there isn't an easy way to do timezone changes in Javascript.

I recommend you use a time library like momentjs. It handles edge cases like daylight savings that you would have to take into account if you do it yourself.

Here's some sample code from another answer:

function toTimeZone(time, zone) {
     var format = 'YYYY/MM/DD HH:mm:ss ZZ';
     return moment(time, format).tz(zone).format(format);
}

https://stackoverflow.com/a/18612568/1031569

You can use the getTimezoneOffset() method of a DateTime to calculate the timezone change, but understand this won't take into account daylights saving or leap year changes.

Sign up to request clarification or add additional context in comments.

Comments

1

Use momentjs. You can choose your format and you just set the country you need

http://momentjs.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.