2009-08-08 42 views

回答

0

如果你在你的项目中使用ASP.NET AJAX已经,达沃·沃德介绍了如何在他的博客Work smarter: MS AJAX's JavScript type extensions使用ASP.NET AJAX扩展用于此目的:

使用Date.format简化客户端日期格式设置 如果您在JavaScript中使用日期的时间很多, 您知道它有时可能有什么麻烦。为了大大缓解这个问题,ASP.NET AJAX扩展了Date对象的格式功能 ,这个格式函数很接近地模仿了我们已经使用多年的 格式化范例。这里有几个例子 :

var today = new Date('12/3/2007'); 

var shortDate = today.format('d'); 
// d formats the date as MM/dd/yyyy 
// shortDate == '12/03/2007' 

var longDate = today.format('D'); 
// D formats the date as dddd, dd MMMM yyyy 
// longDate == 'Monday, 03 December 2007' 

var customDate = today.format('MMMM, yyyy'); 
// Custom format string to format the date as MMMM, yyyy 
// customDate == 'December, 2007' 

Date.format接受大部分 标准DateTime格式字符串,例如 为d和D.如果没有这些套装的你 需求,Date.format还通过 自定义格式化字符串提供了 几乎无限的灵活性。有关格式化字符串参数的完整 列表,请参阅 请参阅MSDN上的Standard DateTime Format StringsCustom DateTime Format Strings参考页。

+0

我需要几分钟和几秒钟...... – mrblah 2009-08-08 01:51:10

+0

底部的链接有各种变化。例如:var myCustomDateTime = today.format('G'); //“09/27/2006 14:15:39” – 2009-08-08 03:36:28

+0

这是怎么结束了你的工作? – 2009-08-10 13:47:49