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 }
时间: 2024-08-03 04:09:32

JS 获取指定URL的时间的相关文章

Js获取指定Url参数

在 C#.PHP.JSP 中,都有直接获取 Url 中指定参数的方法,但 Javascript 却没有这样的现在方法,得自己写一个.在 Web 的开发过程中,获取 Url 中的参数是十分常用的操作,所以很有必要把它封装成一个可直接调用的方法.下面先介绍具体的实现过程,再分享代码. 1.直接获取 Url 中指定参数的实现过程 首先通过 document.location 获得当前访问网页的网址,其次用 split 方法通过“?”把网址分为两部分.如果网址中有参数(arrObj.length > 1

获取指定URl页面中所有链接

//获取指定URL页面中所有链接 function get_url_href($url){ $html = file_get_contents($url); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate('/html/body//a'); for($i=0;$i<$hrefs->length;$i++){ $href =

js 获取当前url参数

2014-7-1 应用在某内网应用排序管理页面跳转: function goSortManage() {    var name = 'TypeID';    var TypeID = "0";    var url = location.search; //获取url中"?"符后的字串     var theRequest = new Object();    if (url.indexOf("?") != -1) {        var s

PHP获取指定URL页面中的所有链接

form:http://www.uphtm.com/php/253.html 这个东西其实我们开发人员来讲常用了,以前做一个抓取其它网站友情连接时用过,今天看到一朋友整理了一个PHP获取指定URL页面中的所有链接函数,整理过来我们一起来看看吧. 以下代码可以获取到指定URL页面中的所有链接,即所有a标签的href属性: // 获取链接的HTML代码 $html = file_get_contents('http://www.111cn.net'); $dom = new DOMDocument(

js获取页面URL地址,判断URL是否包含具体值

window.location.pathname //设置或获取对象指定的文件名或路径window.location.href //设置或获取整个 URL 为字符串window.location.port //设置或获取与 URL 关联的端口号码window.location.protocol //设置或获取 URL 的协议部分window.location.hash //设置或获取 href 属性中在井号"#"后面的分段window.location.host //设置或获取 loc

js获取实时日期和时间

//在相应位置显示时间日期 <div style=" width:400px; height:50px">    <span id="showtime"></span>     <!--走马灯文字 <marquee direction="left">需要滚动的内容</marquee>-->    </div></body> js获取时间日期 <s

js 获取当前页url网址信息

转载地址:js如何准确获取当前页面url网址信息 摘录: 举例一个URL,然后获得它的各个组成部分:http://i.cnblogs.com/EditPosts.aspx?opt=1 1.window.location.href(设置或获取整个 URL 为字符串) var test = window.location.href; alert(test);返回:http://i.cnblogs.com/EditPosts.aspx?opt=1 2.window.location.protocol(

js获取页面url

设置或获取对象指定的文件名或路径. window.location.pathname例:http://localhost:8086/topic/index?topicId=361alert(window.location.pathname); 则输出:/topic/index 设置或获取整个 URL 为字符串.window.location.href例:http://localhost:8086/topic/index?topicId=361alert(window.location.href)

js获取页面url的方法

我们可以用javascript获得其中的各个部分 1, window.location.href 整个URl字符串(在浏览器中就是完整的地址栏) 本例返回值: http://ifisker.com/blog/post/0703/window.location.html# 2,window.location.protocol URL 的协议部分 本例返回值:http: 3,window.location.host URL 的主机部分 本例返回值:www.x2y2.com 4,window.loca