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 A
Solution 1:
You can simply use moment subtract
method.
Here a working sample:
// Current time in Shanghaivar m = moment.tz('Asia/Shanghai');
console.log(m.format('Y-M-D HH:mm:ss'));
// Subtract 9940 hoursconsole.log(m.subtract(9940, 'hours').format('Y-M-D HH:mm:ss'));
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.7/moment-timezone-with-data-2010-2020.min.js"></script>
Note that you should use lowercase mm
to show minutes because uppercase MM
represents months. See format
tokens.
Post a Comment for "Subtracting Hours From Date String"