I am trying to convert Dropbox API date format to date one. In moment.js,
It doesn't work in following format now.
moment.utc("Sat, 21 Aug 2010 22:31:20 +0000")
It does work in following format if using date convert before using utc:
moment.utc(new Date("Sat, 21 Aug 2010 22:31:20 +0000"))
However, I can't use new Date method, because it can't be used in some other cases (string is not standardized) -- related Stackoverflow question.
One possible way is to configure Dropbox input format, is there any other method to let moment.utc work without using new Date method?
Thanks very much!
In the official docs of Moment.js, it says:
Therefore, in order to go around the new Date pitfall and also apply ISO 8061. I can apply
moment()
firstly and then applyutc()
.In that case, although the input string is not formatted as the same(But all follow ISO 8061), they can still be processed safely.
Moments.js issues a big fat Deprecation warning on your code. The gist of the problem is this: if you don't provide an explicit date format, and your date format is not an ISO 8061 lookalike, moment.js gives up on parsing it and relies on new Date() in stead. Which is brittle at best.
The solution is simple: you know the format Dropbox uses to return your date in. Simply specify it, and your problem is solved. Something like (actual format may need some tweaking)