Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

typescript - How to convert dateTime in the correct ISO string with javascript

I try to get the dateTIme in this format:

"2021-01-27T07:30:00Z"

so: yyyy-MM-ddTHH:mm:ssZ

But I get as format like this:

2021-01-27T09:48:00.000Z

So it seems that there is a extra double 00 in it.

So I have it now like this:

startLineChartDate = new Date();
 this.startLineChartDate.setHours(1,0,0, 0);
const startDate = this.startLineChartDate.toISOString();

And I want to start time always on current day with: 00:00:00

But so what I have to change?

Thank you

question from:https://stackoverflow.com/questions/65917820/how-to-convert-datetime-in-the-correct-iso-string-with-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to convert date to ISO String. just use toISOString method. eg;

a = new Date().toISOString();
console.log(a)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...