[英]how I convert EST time data to local time using moment.js / Date in javascript
var res= "03/19/2020 13:15:00"; var res="03/19/2020 13:15:00"; // EST time // 美国东部时间
when i am converting to local timezone当我转换为本地时区时
moment(moment(res.date, 'MM/DD/YYYY HH:mm:ss').utc()).local().format("MM DD YYYY HH:mm:ss")时刻(时刻(res.date, 'MM/DD/YYYY HH:mm:ss').utc()).local().format("MM DD YYYY HH:mm:ss")
I tried many things.我尝试了很多东西。 But I don't know how to convert Est date time to local date time in javascript.但我不知道如何在 javascript 中将 Est 日期时间转换为本地日期时间。
Presumably EST is US Eastern Standard Time, which is GMT+5.据推测,EST 是美国东部标准时间,即 GMT+5。 Most places within that timezone also observe daylight saving, so you may need to determine which set of rules to use.该时区内的大多数地方也遵守夏令时,因此您可能需要确定要使用的规则集。 The offset should be passed with the rest of the timestamp to remove that as a source of error.偏移量应与时间戳的其余部分一起传递,以将其作为错误源删除。
Timezone offsets are usually expressed as the time to add to UTC to get the local time, though ECMAScript (and other programming languages) reverse that, ie the time to subtract from UTC to get local.时区偏移量通常表示为添加到 UTC 以获得本地时间的时间,尽管 ECMAScript(和其他编程语言)反转了这一点,即从 UTC 中减去以获得本地时间的时间。
If the offset of the timestamp is known, then you can parse the string as UTC, then apply the offset, then use plain methods to get local values based on host system settings, eg如果时间戳的偏移量已知,那么您可以将字符串解析为 UTC,然后应用偏移量,然后使用普通方法根据主机系统设置获取本地值,例如
// Offset in minutes, +ve east function parseWithOffset(s, offset) { let b = s.split(/\\D/); let d = new Date(Date.UTC(b[2], b[0]-1, b[1], b[3], b[4], b[5])); d.setUTCMinutes(d.getUTCMinutes() - offset); return d; } let s = '03/19/2020 13:15:00'; // US EST let d = parseWithOffset(s, -300); console.log(d.toString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.