SPServices icon indicating copy to clipboard operation
SPServices copied to clipboard

use date.format in SPConvertDateToISO.js

Open imthenachoman opened this issue 7 years ago • 6 comments

I don't want to muck around with other people's code but wouldn't it make more sense to use Date.format in SPConvertDateToISO.js? (new Date()).format("yyyy-MM-dd HH:mm:ss");

imthenachoman avatar Mar 21 '17 21:03 imthenachoman

Where are you getting this Date#format method from? I don't see it as part of the JavaScript Date class..

(ps> the right method to use is probably toISOString())

purtuga avatar Mar 21 '17 23:03 purtuga

It is included with the JS libraries that MS includes. Check http://sharepoint.stackexchange.com/a/73713/42332. There is also String.format (https://sharepoint.stackexchange.com/questions/160806/changing-date-format-using-javascript).

imthenachoman avatar Mar 22 '17 03:03 imthenachoman

I've rarely wanted to take any dependencies on Microsoft's JavaScript because they used to change it around frequently, with no warning, documentation, or discussion.

.toISOString() is definitely the right way to go these days. I can't remember if I simply didn't know about it at the time or if didn't exist in IE8, which I was usually writing for in the early days.

sympmarc avatar Mar 22 '17 13:03 sympmarc

@sympmarc That is a good point. I've been burned by it myself so I don't blame you.

imthenachoman avatar Mar 22 '17 13:03 imthenachoman

Marc, I don't think IE supported that method in earlier versions, because I too was using a custom function to output ISO dates.


Paul T

purtuga avatar Mar 22 '17 17:03 purtuga

Confirmed, toISOString() is IE9+ only

joshmcrty avatar Mar 22 '17 22:03 joshmcrty