简体   繁体   English

使用javascript for html显示特定时区的日期/日期和时间

[英]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.

相关问题 使用 moment 在特定时区的 utc 从日期到一天的开始时间和结束时间 - From date to day start time and end time in utc in specific timezone using moment 日期-每天的特定时间,特定的时区 - Date - specific time each day, specific timezone Javascript - 显示日期时间并忽略语言环境/时区 - Javascript - Display date time and ignore locale/timezone 从特定时区获取日期和时间 - Getting date and time from a specific timezone Javascript在我的网站上显示日期和时间,使用UTC在javascript中考虑用户时区 - Javascript display date and time in my website using UTC to consider users timezone in javascript 在 javascript 中设置一个独立于浏览器时区和时间的特定日期和时间 - Set a specific date and time in javascript independant of the browser timezone and time 如何使用javascript将本地日期时间转换为UTC并将UTC转换为特定时区? - How to convert Local Date Time to UTC and UTC to specific TimeZone using javascript? 我需要使用 moment.js 根据本地时区转换 UTC 日期和时间,如何将日期从 UTC 转换为 html 中的时区 - I need to convert UTC date and time based on the local timezone using moment.js, how to convert date from UTC to timezone in html 如何使用 javascript 获取特定日期的日期 - How to get the date for a specific day using javascript JavaScript - 在特定时区使用单独的日期和时间值计算 UTC 值 - JavaScript - Compute UTC Value With Separate Date and Time Values in Specific Timezone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM