(E:\workspace_javascript\testingProject\index.js:58:26)Īt Module._compile (internal/modules/cjs/loader. _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: Fri 22:10:42 GMT+0530, _f: undefined, _strict: undefined, _locale: Īt Function.createFromInputFallback (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:320:98)Īt configFromString (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:2368:15)Īt configFromInput (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:2594:13)Īt prepareConfig (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:2577:13)Īt createFromConfig (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:2544:44)Īt createLocalOrUTC (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:2631:16)Īt createLocal (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:2635:16)Īt hooks (E:\workspace_javascript\testingProject\node_modules\moment\moment.js:12:29)Īt Object. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. moment construction falls back to js Date(), which is not reliable across all browsers and versions. datetimefrommoment moment.utc ().utcOffset ('+0530') and then convert it to string so I could save it to firebase realtime database like this: datetimefrommomentstring datetimefrommoment.toString () after sometime I get that datetime (which is in string format) from database to do some calculations. To convert it I do this datetime_converted = moment(datetime_from_moment_string)īut I get this error: Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. How do I do this?Ī string type moment datetime looks like this Fri 22:07:56 GMT+0530 To do those calculations, I have to convert that string to moment type. var ts = moment(" 9:00", "M/D/YYYY H:mm").I calculate datetime using datetime_from_moment = moment.utc().utcOffset('+0530')Īnd then convert it to string so I could save it to firebase realtime database like this: datetime_from_moment_string = datetime_from_moment.toString()Īfter sometime I get that datetime (which is in string format) from database to do some calculations. unix() to return the timestamp in whole seconds, and moment.unix(ts) to parse it back to a moment. Since the input value is interpreted in terms of local time, you will get a different value for ts if you are in a different time zone.Īlso note that if you really do want to work with whole seconds (possibly losing precision), moment has methods for that as well. On my machine, in the US Pacific time zone, it results in: Putting it all together: var ts = moment(" 9:00", "M/D/YYYY H:mm").valueOf() Īlert("Values are: ts = " + ts + ", s = " + s) To answer your questions in comments, No - you don't need to call. Again, you may want to pass a format specifier. If that's not what you expected, you should use the. That won't work because myDate is set to be a Date type. The output format should be specified when calling. If you are near to the date, it will return a value like "Today 9:00 AM". let myDate:Date moment (dateString,'YYYY-MM-DD').format ('DD-MM-YYYY') Basically, when you call moment (), you should specify the format your current date is in, not the output format that you want. So if you replace moment.parseTwoDigitYear in you code, you will have 2069 instead of 1969. This can be changed by replacing the moment.parseTwoDigitYear method. (This is also why you get the deprecation warning in the console.) Instead, provide a format string that matches the expected input, such as: moment(" 9:00", "M/D/YYYY H:mm") From moment docs: By default, two digit years above 68 are assumed to be in the 1900's and years 68 or below are assumed to be in the 2000's. That isn't a good idea, as values like could be interpreted as either February 1st or as January 2nd, depending on the locale of where the code is running. You're parsing a string without providing a format specifier. unix()*1000 would also work, but it would result in a loss of precision. unix() returns Unix Time in whole seconds, but the default moment constructor accepts a timestamp in milliseconds. You probably meant "Unix Time", which is often erroneously called "Epoch Time". You can't convert an arbitrary "date string to epoch". The "Unix Epoch" is Midnight, January 1st 1970 UTC. "Epoch" refers to the starting point of something.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |