Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  106] [ 7]  / answers: 1 / hits: 21782  / 10 Years ago, thu, may 15, 2014, 12:00:00

I'm creating several ISO dates in a Javascript program with the following command:



var isodate = new Date().toISOString()



which returns dates in the format of 2014-05-15T16:55:56.730Z. I need to subtract 5 hours from each of these dates. The above date would then be formatted as 2014-05-15T11:55:56.730Z



I know this is hacky but would very much appreciate a quick fix.


More From » date

 Answers
4

One solution would be to modify the date before you turn it into a string.



var date = new Date();
date.setHours(date.getHours() - 5);

// now you can get the string
var isodate = date.toISOString();


For a more complete and robust date management I recommend checking out momentjs.


[#70986] Wednesday, May 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daveon

Total Points: 749
Total Questions: 108
Total Answers: 87

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;