Monday, 10 April 2017

Subtracting hours from date string

I am working in node js and by using moment-timezone package I have generated a date:

2017-4-10 19:04:47

Below is the code I used to generate this date time which is for timezone Asia/shanghai:

var momentTimezone = require('moment-timezone');
console.log(momentTimezone(new Date()).tz('Asia/shanghai').format('Y-M-D HH:MM:ss'));

Now I want to subtract hours from this time to generate another date. I want to subtract 9940 hours.

I have searched for many hours but could not find exact solution.

Below is the python code which I have to replicate:

 end_time = datetime.now(g.china) 
 //g.china =   timezone("Asia/Shanghai")
 begin_time = end_time - timedelta(hours=9940)

Any guidance over this would be highly appreciated.

Thanks!



via Simer

No comments:

Post a Comment