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

  • 相关阅读:
    移动端疫情展示
    第五周学习进度
    第四周学习进度
    结队开发-四则运算
    第三周学习进度
    全球疫情可视化第一阶段
    第二周学习进度
    面试题 02.07. 链表相交 做题小结
    剑指 Offer 35. 复杂链表的复制 做题小结
    LeetCode 452. 用最少数量的箭引爆气球 做题小结
  • 原文地址:https://www.cnblogs.com/lhat/p/4779587.html
Copyright © 2011-2022 走看看