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 ?
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 ?
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.
Use momentjs. You can choose your format and you just set the country you need