我输入的日期是例如
var startDate = "January 16, 2013"
从我尝试深入研究的旧帖子中,我知道我可能需要使用 http://www.javascripttoolbox.com/lib/date/documentation.php 中的 date.js
所以我在 html 中添加了一行来启动它
<script src="http://prestigeswimming.com/wp-content/plugins/cred-frontend-editor/date.js" type="text/javascript"></script>
<script type="text/javascript">
var startDate = "January 16, 2013"
alert(startDate.getMonthName());
</script>
我应该这样做才能收到一个显示“一月”的警报框吗?
最佳答案
尝试该行的新版本:
var startDate = Date.parseString( "January 16, 2013");
为了使用该库,您必须使用 Date() 对象。
parseString 是该对象上的一个函数,它返回一个 Date 对象。
关于javascript - 将文本输入字符串中的日期转换为其他格式javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14283691/