【问题标题】:Wrong time while getting from full date从完整日期开始时错误的时间
【发布时间】:2018-02-21 18:14:26
【问题描述】:

我正在开发示例 react-native 应用程序。 我正在使用 moment.js 将时间转换为 AM 和 PM 表示。 我的数据是:

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

使用 moment().format('LT') 将 start_dateend_date 转换为 12 小时制格式 (AM/PM) 时,我得到了错误的时间,即 start_date 的时间是晚上 11:59 - end_date 上午 12:59。

我如何获得正确的时间和格式?

【问题讨论】:

  • 2017-09-29T18:29:59.000Z 中的 Z 表示 UTC 时间 - 你是 UTC 时间吗?
  • 我猜你在UTC+5:30 time

标签: javascript datetime react-native momentjs


【解决方案1】:

cmets 是正确的,因为您传递的是2017-09-29T18:29:59.000Z,它会在您的语言环境下变为晚上 11:59。

但是 LT 作为一种格式实际上只会返回时间。尝试使用MM-DD-YYYY hh:mm:ss a 作为格式字符串。

您可以通过moment docs查看更多信息

我还制作了fiddle 供你玩耍。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    相关资源
    最近更新 更多