简体   繁体   English

反应本机:没有调试模式的时刻不适用于特定的时间值

[英]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 helped me 这对我有帮助

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.

相关问题 在 React Native 上没有调试模式的时刻格式时间将成为无效日期 - Moment format the time will become invalid date without debug mode on React Native 套接字仅在调试模式下工作本机反应 - Socket working only with debug mode react native 应用程序在调试模式下崩溃以响应本机日期时间选择器 - App getting crashed in debug mode for react native date time picker 无需登录调试模式即可反应本机应用程序崩溃 - react native app crash without log in debug mode 在调试模式下工作时,本机胜利图表无法在发布模式下工作 - React native victory chart not working in release mode while working in debug mode react-native-geolocation-service 按预期在调试模式下工作正常但在发布模式下不工作 - react-native-geolocation-service working perfectly fine in debug mode as expected but not working in release mode 如何在调试模式下启动React Native应用而无需在开发人员菜单中远程选择调试js - How to start react native app in debug mode without selecting debug js remotely in developer menu Moment JS diff功能在React Native中不起作用 - Moment js diff function is not working in react native Moment js 不适用于 React Native 中的 JSON - Moment js is not working with JSON in React Native 无法在React Native中以调试模式运行应用 - Unable to run app in debug mode in React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM