G.Smith G.Smith - 1 year ago 59
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?

Answer Source

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'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download