我目前有这个

last_modified = xhr.getResponseHeader('Last-Modified');

/* Last-Modified: Wed, 06 Apr 2011 20:47:09 GMT */


但是,对于timeago插件,我需要这种格式

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>


转换最简单,最安全的方法是什么?

最佳答案

尝试使用javascript进行以下操作:

对于标题部分:

    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日”部分:

    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();

09-27 22:19