PHP的时间日期

具体各时间日期函数见:http://www.cnblogs.com/zhouwanqiu/p/9030018.html

一、Unix时间戳

  自格林威治时间(1970年1月1日0时0分0秒)至当前时间的秒数

二、获取当前时间的时间戳

  ①time()

  ②$_SERVER['REQUEST_TIME']

三、获取具体日期时间所对应的时间戳

  mktime(小时,分钟,秒,月,日,年)

  $timenow=time();

  $time01=mktime(20,30,0,8,15,1990);  //1990-8-15 20:30:00

  至今已有:($timenow-$time01) 秒

  至今已有:(($timenow-$time01)/60) 分钟

  至今已有:(($timenow-$time01)/3600) 小时

  至今已有:(($timenow-$time01)/(3600*24)) 天

  至今已有:(($timenow-$time01)/(3600*24*7)) 周

  至今已有:(($timenow-$time01)/(3600*24*7*4)) 月

  至今已有:(($timenow-$time01)/(3600*24*365)) 年

四、获取对应参数的时间戳

  strtotime();

  strtotime("now")  当前时间的时间戳

  strtotime("1 October 1990")  1990年10月1日此时此刻的时间戳

  strtotime("+1 day")  明天该时间的时间戳

  strtotime("+1 week")  下周该时间的时间戳

  strtotime("next Monday")  下周一该时刻的时间戳

  strtotime("last Monday")  上周一该时刻的时间戳

  strtotime("1990-10-1 20:30:00")  指定日期时刻的时间戳

五、获取时间日期

  ①getdate()  返回一个数组

    $today=getdate();

    print_r($today);

    输出:

      array(

        [seconds]=>    秒(0~59)

        [minutes]=>    分钟(0~59)

        [hours]=>     小时(0~23)

        [mday]=>     月份中的第几天(1~31)

        [wday]=>     星期中的第几天(0~6)

        [mon]=>       月(1~12)

        [year]=>       年(4位数字)

        [yday]=>      一年中的第几天(0~365)

        [weekday]=>     星期几的英文(Sunday~Saturday)

        [month]=>       月份的英文(January~December)

        [0]=>       时间戳秒数

      )

  ②date()

    date("Y-m-d H:i:s",$time)  $time为时间戳

六、设置时区

  ①修改PHP的配置文件php.ini

    date.timezone=PRC

  ②在代码中使用函数

    date_default_timezone_set('PRC');

七、获取指定的日期与地点的日出、日落时间

  date_sunrise()  date_sunset()

八、获取脚本运行的微秒数

  microtime(true)  返回一个浮点数

原文地址:https://www.cnblogs.com/zhouwanqiu/p/9262007.html