简体   繁体   English

Date-fns 返回不正确的日期

[英]Date-fns is returning incorrect dates

I have a collection of date strings stored in a database in this format:我有一组以这种格式存储在数据库中的日期字符串:

2018-06-28T14:06:26.524Z

2018-07-02T10:32:18.818Z

2018-07-06T15:08:50.233Z

I need to convert these dates into a format like this on the frontend:我需要在前端将这些日期转换成这样的格式:

28 June 2018 14:06:26

02 July 2018 10:32:18

06 July 2018 08:50:23

My attempt at doing this using date-fns is:我尝试使用 date-fns 执行此操作是:

format(new Date(date), 'dd MMMM yyyy HH:MM:ss')

The problem is that the dates returned from the above are incorrect:问题是从上面返回的日期不正确:

2018-06-28T14:06:26.524Z returns 28 June 2018 15:06:26 2018-06-28T14:06:26.524Z返回28 June 2018 15:06:26

2018-07-02T10:32:18.818Z returns 02 July 2018 11:07:18 2018-07-02T10:32:18.818Z返回02 July 2018 11:07:18

2018-07-06T15:08:50.233Z returns 06 July 2018 16:07:50 2018-07-06T15:08:50.233Z返回06 July 2018 16:07:50

What am I doing wrong here and how to I fix this so the dates are returned correctly?我在这里做错了什么以及如何解决这个问题以便正确返回日期?

You messed up the time:你搞砸了时间:

HH:mm:ss not HH:MM:ss HH:mm:ss不是HH:MM:ss

MM is for month and mm is for minute - docs MM代表月份, mm代表分钟 -文档

You misspelled HH:MM:ss should be HH:mm:ss look at this list for an explanation on all formats: Date formats您拼写错误的HH:MM:ss应该是HH:mm:ss查看此列表以了解所有格式:日期格式

Example:例子:

dd MMMM yyyy HH:mm:ss: 22 August 2006 06:30:07 dd MMMM yyyy HH:mm:ss: 2006 年 8 月 22 日 06:30:07

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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