通过转换毫秒来显示PST中的时间选项

问题描述:

我正在使用javascript。我有毫秒的时间。所以我必须在PST时区显示时间。我曾试过格林威治标准时间但有没有任何选项可以显示PST格式的时间,其中输入以毫秒为单位,如1671673550214.因此,iam试图将此毫秒转换为PST的时间和日期格式。与下面的代码一样。请求帮助。 这里是我试过代码:通过转换毫秒来显示PST中的时间选项

var time = new Date().getTime(); 
    var date = new Date(time); 
     document.write(date.toString()); 

我甚至尝试使用的UTCString(),UTC()和toString();但事情正在转换为格林威治标准时间,而不是PST。

请检查这个库,它有很多功能来显示和manupilate日期时间。

http://momentjs.com/ http://momentjs.com/docs/

同时请参阅下面的帖子

Moment.js: Format date in a specific timezone \

如果你不想使用外部的lib,请参阅下面的文章

http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329

+0

除了使用外部js文件之外,还有什么办法。因为我的数据以毫秒为单位1378740125740 –

+0

请参阅以下文章http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329 –

你可以使用timezonjs w它帮助你把时间转换成任何时区。

https://github.com/mde/timezone-js