.dateParseExact return null

。_饼干妹妹 提交于 2020-01-07 05:23:46

问题


I'm trying to parse the following date:

Tue, 27 Oct 2015 00:00:00 GMT

this is my code:

start = Date.parse(currDateStart.toString('dd/MM/yyyy') 
                                            + ' ' + workingDay.start, 'dd/MM/yyyy HH:mm');

where currDateStart is the date that I want parse (see above), and working.start contains : 09:00 so the final result should be:

Tue, 27 Oct 2015 09:00:00 GMT

but instead I get null why?


回答1:


Neither moment or Date will accept a format parameter in the toString function.

Assuming curreDateStart and the output start are both moment objects, then you should do this:

start = moment(currDateStart.format("YYYY-MM-DD") + ' ' + workingDay.start);

If you wanted Date or string output, you could call toDate or format from there.

If the input is something besides a moment object, then create a moment object from it first, such as moment(currentDateStart) if it's a Date, or moment.utc(currentDateStart, "ddd, DD MMM YYYY HH:mm:ss") if its a string in GMT.



来源:https://stackoverflow.com/questions/33351202/dateparseexact-return-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!