UNIX时间戳:指的是从1970年01月01日起到当前时间所经过的秒数。
一、获取当前时间time()
获取当前时间UNIX的时间戳
<?php
echo time();//1582595180
二、strtotime(string time, [int now])
可以使用某个自然语言创建某个时刻的时间戳。
time:必需。规定日期/时间字符串。
int now:规定用来计算返回值的时间戳,默认是当前时间的时间戳。
<?php
$NowTime=date("Y-m-d H:i:s");
echo strtotime("$NowTime,now"), "<br>";
echo strtotime("now"), "<br>";
echo strtotime("10 September 2014"), "<br>";
echo strtotime("+1 day"), "<br>";
echo strtotime("+1 week"), "<br>";
echo strtotime("+2 week 3 days 2 hours 5 seconds"), "<br>";
echo strtotime("next Thursday"), "<br>";
echo strtotime("last Monday"), "<br>";
?>
三、date(string formate, [int timestramp])函数
日期和时间格式化输出。
string formate:转换时间的格式是什么样的,
timestramp:要转换的时间戳,默认是当前时间的时间戳。
<?php
echo date('Y-m-d H:i:s',1382596802);//2013-10-24 06:40:02
echo date('Y年m月d日 H时i分s秒',1382596802);//2013年10月24日 06时40分02秒
?>
四、getdate([int timestrap])
如果不传值,那么默认的是当前时间。写上参数后就是当前时间戳的时间。这个函数的返回值是一个由时间戳组成的关联数组。具体的键的含义如下:
getdate([int timestrap])
如果不传值,那么默认的是当前时间。写上参数后就是当前时间戳的时间。这个函数的返回值是一个由时间戳组成的关联数组。具体的键的含义如下: