Kevin Meredith
Kevin Meredith

Reputation: 41909

Converting ISO-8601 Timestamp

Is there a JavaScript library function that converts an IS0-8601 time-formatted String:

2015-01-27T00:00:00.328Z

into a String with the following format:

'YYYY.MM.DD HH:MI:SS'?

Example:

convert("2015-01-27T00:00:00.328Z") === "2015.01.27 00:00:00.328"

Upvotes: 1

Views: 891

Answers (1)

Etheryte
Etheryte

Reputation: 25310

If you're going to be using dates more than a simple conversion, you might want to consider using Moment.js.

moment('2015-01-27T00:00:00.328Z').format('YYYY.MM.DD HH:mm:ss'); //Output depends on your timezone

By default moment uses your local time for displaying. If this is not the desired behavior, you can instead use

moment.utc('2015-01-27T00:00:00.328Z').format('YYYY.MM.DD HH:mm:ss'); //"2015.01.27 00:00:00"

Or if you want to include milliseconds:

moment.utc('2015-01-27T00:00:00.328Z').format('YYYY.MM.DD HH:mm:ss.SSS'); //"2015.01.27 00:00:00.328"

Upvotes: 2

Related Questions