js和php获取的时间戳位数不一致问题

JavaScript014

js和php获取的时间戳位数不一致问题,第1张

js获取的时间戳是13位的,精确到毫秒,而php获取的时间戳用strtotime是10位的,这样就导致一般我们在计算倒计时这样的问题时会出现差错,我们可以把js获取的时间戳除以1000,然后再计算

日期插件的包为:mydate.js。

1:首先将日期插件的包引入到页面中

<script language="JavaScript" src="../Inc/Js/mydate.js"></script>

2:设置鼠标点击事件,当鼠标点击获得焦点的时候,触发事件,调用方法

<input type="text" name="starttime" onfocus="MyCalendar.SetDate(this)" value="<?php echo $rq?>">

<input type="text" name="endtime" onfocus="MyCalendar.SetDate(this)" value="<?php echo $rq?>">

3:完整页面代码

<?php

  date_default_timezone_set("PRC")

  $nowtime = time()

  $rq = date("Y-m-d",$nowtime)

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html charset=gb2312" />

<meta name="generator" content="FFKJ.Net" />

<link rev="MADE" href="mailto:[email protected]">

<title>在线--后台</title>

<link rel="stylesheet" type="text/css" href="../Skins/Admin_Style.Css" />

<script language="JavaScript" src="../Inc/Js/mydate.js"></script>

</head>

<body>

开始时间:<input type="text" name="starttime" onfocus="MyCalendar.SetDate(this)" value="<?php echo $rq?>">

结束时间:<input type="text" name="endtime" onfocus="MyCalendar.SetDate(this)" value="<?php echo $rq?>">

</body>

</html>