zoukankan      html  css  js  c++  java
  • 【php学习】时间函数

    手工画了一张图,来大体概括php中对于时间的处理函数

    首先时间戳是这样“1441202665”的一串数字,虽然人看起来麻烦,但是计算机却很容易识别这样的时间表示形式。

    所以给计算机看的时间是时间戳,给人看的是这样的“2015-09-02 22:25:30”字符串。

    time()获取当前时间戳,单位是(s),返回类型是int

    microtime()返回当前时间微妙数和时间戳组成的字符串,如果有true作为参数的话,返回微妙数作为小数部分的浮点数

    strtotime()字符串转换成时间戳,如

    strtotime("2015-09-02");//2015-09-02 00:00:00 的时间戳

    strtotime("2015-09-02 22:39:30"); //返回2015-09-02 22:39:30的时间戳

    再举其他几个例子:

    strtotime("2015/09/02 22:39:30"); 

    strtotime("20150902 22:39:30"); 

    strtotime("20150902 223930"); 

    strtotime("20150902223930");

    以上形式返回结果是相同的

    基本上只要你认真写正常的时间格式字符串,strtotime都能够转成时间戳的。 

     快速生成时间戳

    strtotime("now -1 day"); //昨天

    strtotime("now +1 day"); //明天

    除了day外,还可以使用year、month、week、hour、minute、second。

    date($format, $timestamp) 时间戳转换成字符串

    date('Y-m-d H:i:s', $timestamp)  //返回的字符串如 : 2015-08-07 12:50:35

  • 相关阅读:
    12月11日,12月12日登陆注册页面的进度
    11月28日进度
    11.23JavaScript学习打卡
    11.21,11.22HTML笔记整理
    11.19打卡,HTML学习笔记整理
    select into from 与 insert into select 区别
    解决Cookie乱码
    COOKIE传值
    实现鼠标穿透窗体
    监视鼠标点击了左键还是右键
  • 原文地址:https://www.cnblogs.com/lhat/p/4779587.html
Copyright © 2011-2022 走看看