Kingsley Simon
Kingsley Simon

Reputation: 2210

Convert time string value to time javascript

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

Upvotes: 1

Views: 230

Answers (3)

Arindam Nayak
Arindam Nayak

Reputation: 7462

You can use following.

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

Upvotes: 2

levi
levi

Reputation: 22697

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;

Upvotes: 1

bvaughn
bvaughn

Reputation: 13497

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/

Upvotes: 3

Related Questions