如何在javascript中使用斜杠格式化DateTime字符串以使用超量? [英] How do I format a DateTime string in javascript from using slashes to using hypens?
本文介绍了如何在javascript中使用斜杠格式化DateTime字符串以使用超量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个输入日期字符串,格式如下:
I have an input date string in the following format:
yyyy/mm/dd
这是我想要的输出日期字符串格式:
This is my desired output date string format:
yyyy-mm-dd
是否有内置的方法来执行此操作Javascript?
Is there a built-in way to do this in Javascript?
推荐答案
date = date.replace(/\//g, '-');
如果由于某种原因您不想使用正则表达式
If for some reason you don't want to use a regex
date = date.split('/').join('-');
这篇关于如何在javascript中使用斜杠格式化DateTime字符串以使用超量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文