简体   繁体   English

反应格式字符串日期到日期格式 timzone

[英]React format string date to date format timzone

When I call my function:当我打电话给我的 function 时:

formatDate(new Date("2020-06-08T10:37:05.915+0000")

function formatDate(tstamp) {
  return new Intl.DateTimeFormat("en-GB", {
    year: "numeric",month: "2-digit",day: "2-digit",
    hour: "2-digit", minute: "2-digit",second: "2-digit"
  }).format(tstamp);
}

My output is: 08/06/2020, 12:37:05 why I got (12:37:05) instead (10:37:05) my timezone is GMT+2.我的 output 是:08/06/2020, 12:37:05 为什么我得到 (12:37:05) 而不是 (10:37:05) 我的时区是 GMT+2。

It is because the input is GMT+0000 and you are GMT+0200 which is 2 hours ahead Greenwich Mean Time.这是因为输入是 GMT+0000 而您是 GMT+0200,比格林威治标准时间早 2 小时。 The format method formats a date without changing its time value. format方法格式化日期而不更改其时间值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM