Change ISO Date String to Date Object - JavaScript

前端 未结 8 1736
花落未央
花落未央 2021-01-01 08:54

I am stuck in a weird situation and unfortunately,even after doing some RnD and googling, i am unable to solve this problem.

I have a date string in ISO format, lik

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 09:59

    I also did not care about timestamp/timezone as I am returning only dates from SQL in ISO format. To avoid the day being either one ahead or one behind when converting to Date object, this works:

    moment(ISOStringHere, 'YYYY-MM-DD HH:mm'); // leaving off Z makes it UTC to match database
    

    This requires the Moment JS library located here:

    https://momentjs.com/

提交回复
热议问题