将一种日期格式转换为另一种日期格式 [英] conversion of one date format in to the another
本文介绍了将一种日期格式转换为另一种日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日期
I have a date as
var dt=new Date();
我要转换这个格式化为 dd-mm-yyyy(2011年11月21日)
我无法转换它。
任何人都可以告诉我代码如何转换它?
I want to convert this format in to the dd-mm-yyyy(21-Nov-2011)
I am not able to convert it.
Can anybody tell me the code how can i convert it?
推荐答案
查看以下链接。它将显示不同的日期格式
日期格式
更改示例日期格式:
Check out the following link.It will show you Different Date formates
Date Format
Example to Change Date Format :
<html>
<head>
<script type="text/javascript">
function GetDate()
{
var d=new Date();
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
document.write("The current Date is " + d.getDate() + " " + month[d.getMonth()] + " " + d.getYear());
}
</script>
</head>
<body önload=GetDate()>
</body>
<html>
查看 datejs [ ^ ],这是一个很好的图书馆,可以处理日期javascript更容易
http://www.datejs.com/2007/11/27/getting-started-with-datejs/ [ ^ ]
查看此处的API
http://code.google.com/p/datejs/ [ ^ ]
然后,您可以使用带有格式说明符的toString()方法来获取您需要的格式
Have a look at datejs[^], it's a nice library that makes dealing with dates in javascript much easier
http://www.datejs.com/2007/11/27/getting-started-with-datejs/[^]
Check out the API here
http://code.google.com/p/datejs/[^]
You can then use the toString() method with a format specifier to get the format you require
Date.today().toString('d-M-yyyy')
var now = new Date();
var then = now.getDate()+' - '+ now.getMonth()+' - '+ now.getFullYear( );
alert(then);
var now = new Date();
var then = now.getDate() + '-' + now.getMonth() + '-' + now.getFullYear();
alert(then);
这篇关于将一种日期格式转换为另一种日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文