I have reading moment.js
document, there have a moment.toISOString()
function for helps to formats a string to the ISO8601
standard.
Also there have a another one reason for why we use moment.toISOString()
moment.toISOString()
function using for performance reasons.
I don't know toISOString()
the performance best than moment.toString()
.But only the result was difference while using moment.toString()
and moment.toISOString()
.
Why we should use moment.toISOString()
? for performance reasons?
And what is the difference between moment.toISOString()
and moment.toString()
?
moment().zone is deprecated, use moment().utcOffset instead.
moment. utc can take params as number, string, moment, date etc. This method can be used when the date displayed has to be in UTC format.
Date format conversion with Moment is simple, as shown in the following example. moment(). format('YYYY-MM-DD'); Calling moment() gives us the current date and time, while format() converts it to the specified format.
To add time, pass the key of what time you want to add, and the amount you want to add. moment(). add(7, 'days');
You can give a look directly in momentJS source code for such issue :). Here it is.
export function toString () { return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ'); } export function toISOString () { var m = this.clone().utc(); if (0 < m.year() && m.year() <= 9999) { if ('function' === typeof Date.prototype.toISOString) { // native implementation is ~50x faster, use it when we can return this.toDate().toISOString(); } else { return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); } } else { return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); } }
toString
use .locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ')
which is momentJS source code, executed in JavascripttoISOString()
use javascript Date object (this.toDate().toISOString();
) which is compile and managed by your browser.Native implementation is ~50x faster, use it when we can
However, I think such difference is not relevant for a most projects, but now you know. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With