te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>http - Get time of page loading start in JavaScript - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

http - Get time of page loading start in JavaScript - Stack Overflow

programmeradmin3浏览0评论

In JavaScript it is possible to wait for onLoad which may be used to specify the time of page loading pletion.

Every HTTP response is sent along with Date: header which contains the time server sent a response.

Is there a way in JavaScript to get the time of page started loading? Something similar to response Date: header.

It would be useful for cases when JavaScript is injected into page after some delay.

In JavaScript it is possible to wait for onLoad which may be used to specify the time of page loading pletion.

Every HTTP response is sent along with Date: header which contains the time server sent a response.

Is there a way in JavaScript to get the time of page started loading? Something similar to response Date: header.

It would be useful for cases when JavaScript is injected into page after some delay.

Share Improve this question edited Mar 2, 2014 at 11:18 nilfalse asked Jul 2, 2012 at 14:56 nilfalsenilfalse 2,4192 gold badges20 silver badges17 bronze badges 2
  • 3 The server can write the time into the response in a number of ways: JavaScript code, HTML attribute values, etc. – Pointy Commented Jul 2, 2012 at 14:59
  • Are you looking for "server" date? – Salman Arshad Commented Jul 2, 2012 at 15:32
Add a ment  | 

5 Answers 5

Reset to default 12

new Date(performance.timing.connectStart) in chrome, firefox, IE9, etc (caniuse)

demo

console.log(new Date(performance.timing.connectStart));

Try storing a value from var d= new Date(); var requested = d.getTime(); and execute it when the page loads.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        var loadDate;
    </script>
</head>
<body onload="loadDate=new Date();">
    <button onclick="alert(loadDate);">show load Date</button>
</body>
</html>

Update 2023

As performance.timing.connectStart is deprecated, I remend:

window.performance?.timeOrigin

Here is my code to get something bullet-proof:

    const sessionStartDateTime = window.performance?.timeOrigin ?? window.performance?.timing?.connectStart ?? Date.now();

Sources:

  • window.performance.timing deprecated
  • https://developer.mozilla/en-US/docs/Web/API/PerformanceNavigationTiming

Hope ir helps :)

I would just pass a timestamp from the server-side script to the browser via a cookie or inline JS. E.g. in PHP:

<script>
var timestamp = new Date(<?php echo time(); ?>);
</script>
发布评论

评论列表(0)

  1. 暂无评论