Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecation warning: moment construction falls back to js Date

I am attempting to convert this datetime

150423160509 //this is utc datetime

To the following format:

2015-04-24 00:05:09 //local timezone

by using the moment.js

var moment = require('moment-timezone');


var a = moment.tz('150423160509', "Asia/Taipei");
console.log( a.format("YYYY-MM-DD H:m:s") );

but it gives me this error

Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release
like image 547
jemz Avatar asked Nov 29 '25 12:11

jemz


1 Answers

You need to tell moment how to parse your date format, like this:

var parsedDate = moment.utc("150423160509", "YYMMDDHHmmss");
var a = parsedDate.tz("Asia/Taipei");

// I'm assuming you meant HH:mm:ss here
console.log( a.format("YYYY-MM-DD HH:mm:ss") );
like image 57
Andrew Lavers Avatar answered Dec 02 '25 02:12

Andrew Lavers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!