简体   繁体   中英

Wrong time while getting from full date

I am working on sample react-native app. I am using moment.js to convert time to AM and PM representations. My data is:

{
    "start_date":"2017-09-29T18:29:59.000Z",
    "end_date":"2017-09-29T19:29:59.000Z"
}

When converting the start_date and end_date to 12 hour clock format (AM/PM) using moment().format('LT'), I get the wrong time ie 11:59 PM for start_date - 12:59 AM for end_date .

How do I get the right time and format?

The comments are correct, since you are passing 2017-09-29T18:29:59.000Z it will turn to 11:59pm under your locale.

But LT as a format will really just return the time. Try using MM-DD-YYYY hh:mm:ss a for the format string.

You can check more here at the moment docs

I also made fiddle for you to play around with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM