.dateParseExact 返回 null [英] .dateParseExact return null
问题描述
我正在尝试解析以下日期:
<块引用>2015 年 10 月 27 日,星期二 00:00:00 GMT
这是我的代码:
start = Date.parse(currDateStart.toString('dd/MM/yyyy')+ ' ' + workingDay.start, 'dd/MM/yyyy HH:mm');
其中 currDateStart 是我想要解析的日期(见上文),并且 working.start
包含: 09:00
所以最终结果应该是:
2015 年 10 月 27 日,星期二 09:00:00 GMT
但我得到 null
为什么?
moment
或 Date
都不会接受 toString
中的格式参数功能.
假设 curreDateStart
和输出 start
都是 moment
对象,那么你应该这样做:
start = moment(currDateStart.format("YYYY-MM-DD") + ' ' + workingDay.start);
如果你想要 Date
或 string
输出,你可以从那里调用 toDate
或 format
.>
如果输入是 moment
对象之外的东西,那么首先从它创建一个 moment
对象,例如 moment(currentDateStart)
if它是一个 Date
,或者 moment.utc(currentDateStart, "ddd, DD MMM YYYY HH:mm:ss")
如果它是一个 string
格林威治标准时间.
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?
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.
这篇关于.dateParseExact 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!