React native : moment not working for specific time value without debug mode

后端 未结 1 1729
無奈伤痛
無奈伤痛 2020-12-22 11:09

I have below code where I format the time value to be date format.

 const arrivalDateTime = moment(
   `${todaysDate.format(\"YYYY-MM-DD\")} ${arrivalTime}:         


        
相关标签:
1条回答
  • 2020-12-22 11:54

    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.

    0 讨论(0)
提交回复
热议问题