JS 获取指定URL的时间

 1 //获得指定URL的时间

 2 function gettimestr() {

 3     var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");

 4     try {

 5         xmlhttp.open("GET", "http://open.baidu.com/special/time/", false);

 6         xmlhttp.setRequestHeader("If-Modified-Since", "q");

 7         xmlhttp.send();

 8         var dateStr = xmlhttp.getResponseHeader("Date");

 9     }

10     catch (err) {

11         //Get local time, if error

12         var time = "";

13         var date = new Date();

14         var year = date.getFullYear();

15         var month = date.getMonth() + 1;

16         var day = date.getDay() + 1;

17         var hour = date.getHours();

18         var minute = date.getMinutes();

19         var second = date.getSeconds();

20         time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

21         return time;

22     }

23     var d = new Date(dateStr);

24     var str = d.getFullYear() + "-";

25     var Month = d.getMonth() + 1;

26     if (Month < 10) str = str + "0";

27     str = str + Month + "-";

28     if (d.getDate() < 10) str = str + "0";

29     str = str + d.getDate() + " ";

30     if (d.getHours() < 10) str = str + "0";

31     str = str + d.getHours() + ":";

32     if (d.getMinutes() < 10) str = str + "0";

33     str = str + d.getMinutes() + ":";

34     if (d.getSeconds() < 10) str = str + "0";

35     str = str + d.getSeconds();

36     return str;

37 }

 

你可能感兴趣的:(url)