1

I have this time value

2000-01-01T10:00:00.000Z

How do i convert it in javascript to only return the time

10:00

3 Answers 3

3

If you strip off the training ".000Z" then you can use Moment JS:

var m = moment('2000-01-01T10:00:00', moment.ISO_8601);
m.format('HH:mm'); // 10:00

See http://momentjs.com/docs/#/parsing/string/

Sign up to request clarification or add additional context in comments.

Comments

2

You can use following.

var k = new Date("2000-01-01T10:00:00.000Z");
alert(k.getUTCHours() + ":" + k.getUTCMinutes());

3 Comments

This is because your timezone is -8 hrs, and time need to convert to match your timezone.
Your example should use UTC hours/minutes to account for the fact that people live in different timezones.
Fixed, you might need to pad with 0s , if you want.
1

Using pure javascript, create date object with new Date() then use getUTCHours() and getUTCMinutes()

 var date = new Date("2000-01-01T10:00:00.000Z");
 var hour = date.getUTCHours()();
 var minutes = date.getUTCMinutes();
 var time = hour + ":" + minutes;

1 Comment

@brianvaughn I fixed, now Im using UTC methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.