我有一长串日期。看起来是这样: 2012年6月18日19:00:00。我的问题很简单。我希望它是这样显示的: dd/mm/yyyy HH:mm (HH实现24小时) im使用jQuery和它的所有UI。请不要告诉我添加这个Date.js类。当然可以通过简单的jQuery来完成:)谢谢!
发布于 2012-06-18 08:02:26
因为您已经加载了jQueryUI,所以内置了一个完整的日期格式化实用程序,但它不处理时间。除此之外,您还需要自己处理原生javscript Date对象,或者使用像date.js这样的数据库来简化解析。
使用jQUeryUI的示例:http://jsfiddle.net/qqLMd/
var newDate=$.datepicker.formatDate('yy-mm-dd', new Date('Mon Jun 18 2012 19:00:00'); http://docs.jquery.com/UI/Datepicker/formatDate
您确信这是一个简单的jQUery过程是错误的。jQuery在核心API中没有任何日期处理。
发布于 2012-06-18 07:44:07
您可以使用substring()方法。
var longDate = 'Mon Jun 18 2012 19:00:00';
var date = longDate.substring(8,10);
var month = longDate.substring(4,7);
var year = longDate.substring(11,15);
var hours = longDate.substring(16,18);
var minutes = longDate.substring(19,21);
if(month == "Jan")
month = "01";
else if(month == "Feb")
month = "02";
else if(month == "Mar")
month = "03";
else if(month == "Apr")
month = "04";
else if(month == "May")
month = "05";
else if(month == "Jun")
month = "06";
else if(month == "Jul")
month = "07";
else if(month == "Aug")
month = "08";
else if(month == "Sep")
month = "09";
else if(month == "Oct")
month = "10";
else if(month == "Nov")
month = "11";
else if(month == "Dec")
month = "12";
var oriDate = date + "/" + month + "/" + year + " ";
if(hours == 0)
oriDate += "00:";
else
oriDate += hours + ":";
if(minutes == 0)
oriDate += "00";
else
oriDate += minutes;
alert(oriDate); // 18/06/2012 19:00在这里检查jsfiddle:http://jsfiddle.net/reygonzales/v2tSb/
https://stackoverflow.com/questions/11075601
复制相似问题