[英]Display day/date and time from specific timezone using javascript for html
I have a project that requires the day, date, and time to be displayed on a website from a specific timezone, Central European Time. 我有一个项目,要求从特定时区(中欧时间)在网站上显示日期,日期和时间。 Ideally I'd like to display it in this format:
理想情况下,我想以以下格式显示它:
Tue 4 May 05:52:33 CET 欧洲中部时间5月4日星期二05:52:33
I've been able to get the time to display on websites before, but this is usually getting the time from the user's end. 我以前已经有时间在网站上显示,但这通常是从用户的角度出发。 In this case it should display my time.
在这种情况下,它应该显示我的时间。
I know there are quite a few topics about this already, but I really haven't been able to get it to work, plus including the day and date is an additional difficulty. 我知道已经有很多关于此的主题,但是我确实还没能使它正常工作,而且加上日期和日期是另外一个难题。
Any help would be amazing :-) 任何帮助都将是惊人的:-)
Use the moment.js library. 使用moment.js库。
Let's say your timezone is "America/Los_Angeles": 假设您的时区为“ America / Los_Angeles”:
var myTimezone = "America/Los_Angeles";
var datetimeFormat = "ddd DD MMM hh:mm:ss z";
var timeString = moment().tz(myTimezone).format(datetimeFormat);
console.log(timeString);
This will format the user's time into your timezone. 这会将用户的时间格式化为您的时区。 For more information, see: http://momentjs.com/timezone/
有关更多信息,请参见: http : //momentjs.com/timezone/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.