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
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") );
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