Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我需要从'1609891200000'开始的正确时间,而不使用时刻,但我不';I don’我不知道为什么我的时间一直是5:30_Javascript_Date_Momentjs_Moment Timezone - Fatal编程技术网

Javascript 我需要从'1609891200000'开始的正确时间,而不使用时刻,但我不';I don’我不知道为什么我的时间一直是5:30

Javascript 我需要从'1609891200000'开始的正确时间,而不使用时刻,但我不';I don’我不知道为什么我的时间一直是5:30,javascript,date,momentjs,moment-timezone,Javascript,Date,Momentjs,Moment Timezone,我需要一种方法来获得正确的时间,即12:00 AM,而不使用时间。 有人能帮忙吗?你应该提供时区代码, 如果没有代码,那么它将默认提供 var now = moment(1609891200000, "x").format('MMM DD h:mm A'); var x = new Date(1609891200000); console.log(now); // Prints Jan 06 12:00 AM console.log(x.toLocaleTimeString(

我需要一种方法来获得正确的时间,即
12:00 AM
,而不使用时间。
有人能帮忙吗?

你应该提供时区代码, 如果没有代码,那么它将默认提供

var now = moment(1609891200000, "x").format('MMM DD h:mm A');
var x = new Date(1609891200000);
console.log(now); // Prints Jan 06 12:00 AM
console.log(x.toLocaleTimeString()); // Prints 05:30:00
相反,您可以使用

var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));

// toLocaleTimeString() without arguments depends on the implementation,
// the default locale, and the default time zone
console.log(date.toLocaleTimeString());
// → "7:00:00 PM" if run in en-US locale with time zone America/Los_Angeles

您还可以使用下一个选项:
newdate(1609891200000)。toLocaleTimeString('en-US',{hour12:true,hour:'2位',timeZone:'UTC',timeZoneName:'short',minute:'2位'})
/“UTC上午12:00”
var x = new Date(1609891200000);
x.toGMTString() // "Wed, 06 Jan 2021 00:00:00 GMT"
x.toUTCString() // "Wed, 06 Jan 2021 00:00:00 GMT"
x.toISOString() // "2021-01-06T00:00:00.000Z"