G.Smith G.Smith - 4 months ago 12
AngularJS Question

Moment js not finding the time

I am using angularJs and moment js. I have a textbox that sends for example

12:00 PM

to the function (apptime) - i then do

var newtime = moment(apptime,'hh:mm:ss');

and this is what the console outputs :

Thu Jan 01 1970 12:00:00 GMT+0000 (GMT Standard Time)

so it is getting the time fine, i see 12:00:00 there..

then(because of the database structure) i want to convert it to this :

1899-12-30 12:00:00

so i do this :

console.log("1899-12-30 " + newtime.format('hh:mm:ss'));

and no matter what the date is, the response is always

1899-12-30 01:00:00

Why is it thinking 01 is the hour?


It should convert to UTC time.


console.log("1899-12-30 " + newtime.format('hh:mm:ss'));


console.log("1899-12-30 " + moment(newtime).utc().format('hh:mm:ss'));