将Unix时间戳转换为PST [英] Converting Unix Timestamp to PST

查看:265
本文介绍了将Unix时间戳转换为PST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个json,我正在获取一些数据.那里的时间格式就像

Hi I have a json which I am getting some data. There the time format I am getting is like

1367023443000

我要将其转换为普通PST格式.香港专业教育学院尝试使用Javascript的Date方法.将Unix时间传递给Date方法,

I want to convert this to the Normal PST format. Ive tried using Javascript`s Date method. Passed the Unix time to the Date method,

var now = new Date(1367023443000); 

我仅获得IST值,而不是PST.我应该怎么做才能将Unix时间戳转换为PST?

I am getting only IST value, But not PST. What should I do here to convert the Unix timestamp to PST?

推荐答案

如果您实际上不在美国太平洋时区,则在JavaScript中可靠地执行此操作的唯一方法是使用实​​现TZDB数据库的库. 我在这里列出了其中的几个.

If you're not actually in the US Pacific Time zone, the only way to do this reliably in JavaScript is with a library that implements the TZDB database. I list several of them here.

例如,使用 walltime-js 库,您可以执行以下操作:

For example, using walltime-js library, you can do the following:

var date = new Date(1367023443000);
var pacific = WallTime.UTCToWallTime(date, "America/Los_Angeles");
var s = pacific.toDateString() + ' ' + pacific.toFormattedTime();

// output:  "Fri Apr 26 2013 5:44 PM"

您不能只添加或减去一个固定数字,因为目标时区可能会使用不同的偏移量,具体取决于您所谈论的日期.这主要是由于夏时制,也是由于时区随时间而变化.

You can't just add or subtract a fixed number, because the target time zone may use a different offset depending on exactly what date you're talking about. This is primarily due to Daylight Saving Time, but also because time zones have changed over time.

这篇关于将Unix时间戳转换为PST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆