Reputation: 2210
I have the following row in my database in rails.
time: 10:00:00
In my javascript code, I call the data from the database and time is returned in in this format '2000-01-01T10:00:00.000Z'. Time set in database is 10:00:00.
How do i get the time in HH:MM format in javascript.
If i do this,
var time = 2000-01-01T10:00:00.000Z;
console.log(time.getHours());
i get an error. any help appreciated.
Thanks
Upvotes: 0
Views: 394
Reputation: 12815
You need to convert your time to a Date. Right now, it's just a string, so that is why you're getting "undefined is not a function" as your error.
var time = new Date('2000-01-01T10:00:00.000Z');
console.log(time.getHours() + ':' + time.getMinutes());
Upvotes: 1