瞬间格式返回无效日期 [英] Moment format returns invalid date

查看:64
本文介绍了瞬间格式返回无效日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用瞬间格式化的日期,显示如下:2105年3月4日.我想再次使用矩将其转换为iso.结果,我在写:

i have a date which i formated using moment to be shown like this: 03/04/2105. I want to transform it to iso using moment again. As a result i'm writing:

const IsoDateTo = moment(dateTo).format('YYYY-MM-DD[T]HH:mm:ss');

日期为23/04/2105,但是IsoDateTo返回如下内容:2105-03-04T00:00:00另外,当我输入的日期大于12时,它也会返回无效日期.为什么会这样?

The date to is 23/04/2105 but the IsoDateTo is returning something like this: 2105-03-04T00:00:00 Also when i enter a date greater than 12 it returns me Invalid Date. Why is this happening?

推荐答案

要确保正确解析了您想要将期望的字符串格式传递给momentjs的字符串(类似这样):

To make sure that you are correctly parsing the string you want to pass the expected string format along to the momentjs (something like this):

const IsoDateTo = moment(dateTo,'DD/MM/YYYY').format('YYYY-MM-DD[T]HH:mm:ss');

这篇关于瞬间格式返回无效日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆