search

Home  >  Q&A  >  body text

There are differences between the two methods of obtaining timestamps in PHP. Why?

Try to use two methods of php to obtain the current timestamp. There are differences, but the two timestamps are converted into time at the same time point. I checked the unit of the timestamp on the network is seconds. Why is this happening?


$currentDay = getdate();
//var_dump($currentDay);
//2.1 获取当前的日期
//echo $currentDay["year"]."-".$currentDay["mon"]."-".$currentDay["mday"]."<br/>";
echo "时间戳为1:".strtotime(date("Y-m-d h:m:s"))."<br/>";
echo "时间戳为2:".$currentDay[0]."<br/>";
$time1 = strtotime(date("Y-m-d h:m:s"));
echo "不同的时间为:".date("Y-m-d H:m:s a",$currentDay[0])."--".date("Y-m-d H:m:s a",$time1);

The output result is:
The timestamp is 1:1492131843
The timestamp is 2:1492134903
The different times are: 2017-04-14 09:04:03 am--2017-04- 14 09:04:03 am

给我你的怀抱给我你的怀抱2795 days ago638

reply all(5)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:16:11

    strtotime(date("Y-m-d h:m:s"))
    

    should be:

    strtotime(date("Y-m-d h:i:s"))

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:16:11

    It is recommended that the poster read more php manual. Link

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 13:16:11

    https://www.bytelang.com/o/s/...

    You wrote it wrong yourself!

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:16:11

    You wrote it wrong yourself

    reply
    0
  • ringa_lee

    ringa_lee2017-05-16 13:16:11

    Year, month, day, hours, minutes and seconds correspond to Y-m-d h:i:s

    reply
    0
  • Cancelreply