如何更改JavaScript中的日期格式? [英] How to change Date format in JavaScript?
本文介绍了如何更改JavaScript中的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在JavaScript中更改日期的格式。我试过
I want to change a date's format in JavaScript. I tried
var today = new Date();
today.toLocaleFormat('%d-%b-%Y');
但没有工作。如何处理这个问题?
but that didn't work. How can I approach this problem?
推荐答案
我认为没有直接的方法。让我们检查一下:
I think there is no straight way to do so. Let's check these out:
var date = new Date();
var options = {
weekday: "long", year: "numeric", month: "short",
day: "numeric", hour: "2-digit", minute: "2-digit"
};
//alert(date.toLocaleDateString("en-US"));
alert(date.toLocaleTimeString("en-us", options));
我认为您正在寻找:
var myDate = new Date();
alert(myDate.getDate() + "-" + (myDate.getMonth() + 1)+ "-" + myDate.getFullYear());
是的,我已经google了,得到了这个解决方案。请检查。 :)
谢谢!
Yes, I've googled and got this solution. Please check it out. :) Thanks!
这篇关于如何更改JavaScript中的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文