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; } ?>Why is Javascript Date.now() returning the wrong date? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why is Javascript Date.now() returning the wrong date? - Stack Overflow

programmeradmin3浏览0评论

When tested in the Firefox Javascript console,

Date.now();

returns 1433959098918.

Googling "1433959098918 ms in years" returns 45.4404 years, which added to January 1st 1970 00:00:00 is May 8th, 2015. I have also tried

(new Date()).getTime();

which returns the same result. Am I miscalculating something and if not, why is Date.now() returning this result?

EDIT: Nevermind, my calculation was incorrect. I assumed that dates are 0 based and they are not.

When tested in the Firefox Javascript console,

Date.now();

returns 1433959098918.

Googling "1433959098918 ms in years" returns 45.4404 years, which added to January 1st 1970 00:00:00 is May 8th, 2015. I have also tried

(new Date()).getTime();

which returns the same result. Am I miscalculating something and if not, why is Date.now() returning this result?

EDIT: Nevermind, my calculation was incorrect. I assumed that dates are 0 based and they are not.

Share Improve this question edited Jun 10, 2015 at 18:15 Iambrett3 asked Jun 10, 2015 at 18:06 Iambrett3Iambrett3 611 silver badge4 bronze badges 2
  • Your assumption is not correct, 1433959098918 = Wed, 10 Jun 2015 17:58:18 GMT so there seems to be no problem here – Claudio Redi Commented Jun 10, 2015 at 18:13
  • "Am I miscalculating something". Well yes you are. As .4404 years are 160 days, now you can count – bugwheels94 Commented Jun 10, 2015 at 18:17
Add a ment  | 

2 Answers 2

Reset to default 11

Because the js timestamp is not the unix timestamp, the unix timestamp is in seconds not in miliseconds you need divided for 1000, you can remove the last 3 digits

1433959098918 -> 1433959098

This different format have a lot of problems if you don't know it. :)

Right now:

(new Date()).getTime()

Gives me:

1433959813432 (or 45,4 years)

Which is correct. You made an error in your putation:

1433959813432 [ms] / 60 [s/m] / 60 [m/h] / 24 [h/d] / 365.25 [d/y]
= 45.439444489821786194133901183867 [y]

You need to count 365.25 days per year to include leapyears.

It's not perfect AT ALL but it's a good approximation.

Add 1970 years and you get:

2015.4394444898217861941339011839

Which is the year 2015 plus the rest, which is:

0.4394444898217861941339011839 [y] * 365.25 [d/y]

Or:

160.50709990740740740740740740742 days

Now, deduct 31 days for january, 28 for february, 31 march, 30 for april and 31 for may and you get:

9.5070999074074074074074074074218 days into june

Which is the 10th day june of 2015 (count from 0).

The rest is:

0.5070999074074074074074074074218 * 24 hours
= 12.170397777777777777777777778123 hours

Plus my timezone and DST and it's just on spot!

发布评论

评论列表(0)

  1. 暂无评论