如何使用jquery/javascript转换时间/日期? [英] How to convert time / date with jquery/javascript?
本文介绍了如何使用jquery/javascript转换时间/日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有这个
last_modified = xhr.getResponseHeader('Last-Modified');
/* Last-Modified: Wed, 06 Apr 2011 20:47:09 GMT */
但是,对于 timeago 插件,我需要这种格式
However, for the timeago plugin i need this format
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
最简单,最安全的转换方式是什么?
What would be the most easy and bulletproof way to convert?
推荐答案
使用javascript尝试以下操作:
Try this using javascript as follows:
对于标题部分:
var dateObj = new Date(last_modified);
var newDate = dateObj .getFullYear() + "-" + dateObj.getMonth() + "-" + dateObj.getDate() + "T" + dateObj.getHours() + ":" + dateObj.getMinutes() + ":" + dateObj.getSeconds() + "Z";
对于"2008年7月17日"部分:
For the "July 17, 2008" part:
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var dateObj = new Date(last_modified);
var anotherDate = m_names[dateObj.getMonth()] + " " + dateObj.getDate() + ", " + dateObj.getFullYear();
这篇关于如何使用jquery/javascript转换时间/日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文