[英]React native : moment not working for specific time value without debug mode
I have below code where I format the time value to be date format.我有下面的代码,我将时间值格式化为日期格式。
const arrivalDateTime = moment(
`${todaysDate.format("YYYY-MM-DD")} ${arrivalTime}:00:00`,
).toDate();
When debug mode is off, if I select 8 or 9 value from the control, its not able to format the value.当调试模式关闭时,如果我 select 来自控件的 8 或 9 值,则无法格式化该值。
When I am in debug mode, and select 8 or 9, its able to format the value as:当我处于调试模式并且 select 8 或 9 时,它能够将值格式化为:
Fri May 22 2020 09:00:00 GMT-0600 (Mountain Daylight Time)
I have seen many threads discussing the same issue but solution provided in them haven not helped me to format this correctly.我看到许多线程讨论相同的问题,但其中提供的解决方案并没有帮助我正确格式化。
I am trying to print arrivalDateTime value, it shows like this in log;我正在尝试打印到达日期时间值,它在日志中显示如下;
Date { NaN }
I am trying this but it does not work, it days toDate is not a function:我正在尝试这个,但它不起作用,它的日子 toDate 不是 function:
moment().format(`YYYY-MM-DD ${arrivalTime}:00:00`).toDate();
Took me a while but I finally figured it out.花了我一段时间,但我终于弄明白了。
This didn't work:这没有用:
const arrivalDateTime = moment(
`${todaysDate.format("YYYY-MM-DD")} ${arrivalTime}:00:00`,
).toDate();
This worked:这有效:
const arrivalDateTime = moment(
`${todaysDate.format('YYYY/MM/DD')} ${arrivalTime}:00`,
).toDate();
// note that engine does not seem to like parsing with ' - '. // 请注意,引擎似乎不喜欢使用 ' - ' 进行解析。 so I changed it to ' / '所以我把它改成'/'
still not sure the reason behind it.仍然不确定其背后的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.