使用/不使用Moment.js的日期格式 [英] date formatting with/without Moment.js

查看:133
本文介绍了使用/不使用Moment.js的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新格式化一个我从API获得的日期。在对象中我有:

  created_at:2013-06-13T16:29:55.245Z

我想将日期显示为6/13/2013。有人建议我使用moment.js。它有大量的文档,但我有点困惑如何使用它。有人可以帮忙还是建议一个更简单的方法呢?

解决方案

无需修改原始字符串,您可以这样使用:

  alert(moment(2013-06-13T16:29:55.245Z)。format(M / DD / YYYY)); 

效果很好: http://jsfiddle.net/K5ub8/2/


I am trying to reformat a date that I am getting from an API. In the object I have:

created_at: "2013-06-13T16:29:55.245Z"

I would like to display the date as 6/13/2013. Someone suggested I use moment.js. It has tons of documentation but i'm a bit confused on how to use it. can someone please help or suggest an easier way to do this?

解决方案

No need to modify the original string, you can just use it like this:

alert(moment("2013-06-13T16:29:55.245Z").format("M/DD/YYYY"));

Works well: http://jsfiddle.net/K5ub8/2/

这篇关于使用/不使用Moment.js的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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