在javascript中格式化日期字符串 [英] Format a date string in javascript
本文介绍了在javascript中格式化日期字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好每个我都有类型字符串的日期字段,其格式如下:
const date =2017-06-10T16:08:00:我想以某种方式编辑以下格式的字符串,如下所示: 10-06-2017但我正在努力实现这一点。
我在T字符之后剪切子字符串
Hello every i have date field of type string with iso format like this: const date = "2017-06-10T16:08:00: i want somehow to edit the string in the following format like this: 10-06-2017 but i'm struggling in achieving this. I cut the substring after the "T" character
推荐答案
使用 Moment.js 和 .format
功能。
moment('2017-06-10T16:08:00').format('MM/DD/YYYY');
将输出
06/10/2017
除了格式
函数 Moment.js 将丰富您将获得更多有用的功能。
Beside the format
function Moment.js will enrich you will alot more useful functions.
这篇关于在javascript中格式化日期字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文