Javascript 这种格式是什么意思 T00:00:00.000Z?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28949911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does this format means T00:00:00.000Z?
提问by Ali Akram
Please someone explain this type of format in javascript
请有人在javascript中解释这种类型的格式
T00:00:00.000Z
And how to parse it.
以及如何解析它。
Thanks
谢谢
回答by nanndoj
It's a part of ISO-8601date representation. It's incomplete because a complete date representation in this pattern should also contains the date:
它是ISO-8601日期表示的一部分。这是不完整的,因为此模式中的完整日期表示还应包含日期:
2015-03-04T00:00:00.000Z //Complete ISO-8601 date
If you try to parse this date as it is you will receive an Invalid Dateerror:
如果您尝试按原样解析此日期,则会收到Invalid Date错误消息:
new Date('T00:00:00.000Z'); // Invalid Date
So, I guess the way to parse a timestamp in this format is to concat with any date
所以,我想解析这种格式的时间戳的方法是连接任何日期
new Date('2015-03-04T00:00:00.000Z'); // Valid Date
Then you can extract only the part you want (timestamp part)
然后你可以只提取你想要的部分(时间戳部分)
var d = new Date('2015-03-04T00:00:00.000Z');
console.log(d.getUTCHours()); // Hours
console.log(d.getUTCMinutes());
console.log(d.getUTCSeconds());
回答by gone43v3r
i suggest you use moment.jsfor this. In moment.js you can:
我建议你用moment.js这个。在 moment.js 中,您可以:
var localTime = moment().format('YYYY-MM-DD'); // store localTime
var proposedDate = localTime + "T00:00:00.000Z";
now that you have the right format for a time, parse it if it's valid:
既然您有一段时间的正确格式,请解析它是否有效:
var isValidDate = moment(proposedDate).isValid();
// returns true if valid and false if it is not.
and to get time parts you can do something like:
并获得时间部分,您可以执行以下操作:
var momentDate = moment(proposedDate)
var hour = momentDate.hours();
var minutes = momentDate.minutes();
var seconds = momentDate.seconds();
// or you can use `.format`:
console.log(momentDate.format("YYYY-MM-DD hh:mm:ss A Z"));
More info about momentjs http://momentjs.com/
有关 momentjs 的更多信息http://momentjs.com/
回答by that_developer
As one person may have already suggested,
正如有人可能已经建议的那样,
I passed the ISO 8601date string directly to moment like so...
我像这样直接将ISO 8601日期字符串传递给 moment...
`moment.utc('2019-11-03T05:00:00.000Z').format('MM/DD/YYYY')`
or
或者
`moment('2019-11-03T05:00:00.000Z').utc().format('MM/DD/YYYY')`
either of these solutions will give you the same result.
这些解决方案中的任何一个都会为您提供相同的结果。
`console.log(moment('2019-11-03T05:00:00.000Z').utc().format('MM/DD/YYYY')) // 11/3/2019`
回答by Shahid Hussain Abbasi
Please use DateTimeFormatter ISO_DATE_TIME = DateTimeFormatter.ISO_DATE_TIME;instead of DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss")or any pattern
请使用 DateTimeFormatterISO_DATE_TIME = DateTimeFormatter.ISO_DATE_TIME;而不是DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss")任何模式
This fixed my problem Below
这解决了我的问题
java.time.format.DateTimeParseException: Text '2019-12-18T19:00:00.000Z' could not be parsed at index 10
java.time.format.DateTimeParseException:无法在索引 10 处解析文本“2019-12-18T19:00:00.000Z”
回答by mango developer
I used this code inside nodejs
我在 nodejs 中使用了这段代码
let result = moment().subtract(age, "years").format("YYYY-MM-DD")+"T00:00:00.000Z";
return res.json(result);
//result is
// "2001-11-27T00:00:00.000Z"
I subtracted 18 years.
我减去了 18 年。
It will help you for nodejs queries.
它将帮助您进行 nodejs 查询。

