0
function getDateFromUrl(url)
{
var urlDateString = url.substring(url.lastIndexOf('/day/')+5);

urlDateString =urlDateString.replace("/index-1.html","");
urlDateString =urlDateString.replace("th",""); 
urlDateString =urlDateString.replace("rd",""); 
urlDateString =urlDateString.replace("st",""); 
urlDateString =urlDateString.replace(","," "); 
urlDateString =urlDateString.replace("/"," "); 
urlDateString =urlDateString.replace("-"," ");
urlDateString =urlDateString.replace("."," ");
urlDateString =urlDateString.replace(","," "); 
urlDateString =urlDateString.replace("/"," "); 
urlDateString =urlDateString.replace("-"," ");
urlDateString =urlDateString.replace("."," ");

return new Date(urlDateString);
}

function getDayFromDate(dt)
{

 switch (dt.getDay())
 {
 case 0:
   x="Sunday";
   break;
 case 1:
   x="Monday";
   break;
 case 2:
   x="Tuesday";
   break;
 case 3:
   x="Wednesday";
   break;
 case 4:
   x="Thursday";
   break;
 case 5:
   x="Friday";
   break;
 case 6:
   x="Saturday";
   break;
 }
return x;
}

http://jsfiddle.net/FyEMD/

IE 和opera 不支持这个脚本。因为它们不输出日期,而 chrome 和 firefox 确实输出日期。会不会是因为他们不支持字符串格式的日期。如果是这样,日期必须采用哪种格式。

输入看起来像 C:\example\day\12-October-12 输出应该是 date: Oct 12 2012 day: Friday 代码的方式是 atm 它在 chrome 和 firefox 中工作

任何帮助表示赞赏。

4

1 回答 1

0

使用以下格式之一进行跨浏览器Date构建:

"2010"

"2010-06"

"2010-06-09"

"2010-06-09T15:20:00Z"

"2010-06-09T15:20:00-07:00"

"2010/06/09"

"2009/6/9"

"2010/6/9 12:34"

"2010/6/9 12:34:56"

"June 9, 2010"

"2010 June 9"
于 2014-02-13T20:40:23.370 回答