将我的日期显示为特定格式

时间:2014-09-12 12:40:33

标签: javascript datetime

我对此有点困难。如何使用Javascript显示格式10 September 2014的日期值。

我现在正在做的是

var dateAdded = new Date(parseInt(user.DateAdded.substr(6)));

给了我Wed Sep 10 2014

1 个答案:

答案 0 :(得分:1)

How to format a JavaScript date

的副本

但Marko接受了你的回答:

取自http://www.webdevelopersnotes.com/tips/html/javascript_date_and_time.php3

<script type="text/javascript">
<!--

var m_names = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(curr_date + "-" + m_names[curr_month] 
+ "-" + curr_year);

//-->
</script>

您可以编辑数组以使用Jan,Feb,Mar等。