简体   繁体   中英

By passing string from query parameter in moment() shows moment.invalid

I am making GET api under which I want date time in query parameter. If I simply make log with req.query() it is showing correct string. But if I pass that string in moment() then I am getting moment.invalid('date').

Here is my code:

console.log('current time ', req.query.currentTime, moment(req.query.currentTime));

and in console, I am getting,

 moment.invalid(/* DATE */)

As your date string contains timezone. You can convert it using following way:

moment().parseZone(date).format('YYYY-MM-DD');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM