• php date操作


    date(format,timestamp)

    • d - 月中的天 (01-31)
    • m - 当前月,以数字计 (01-12)
    • Y - 当前的年(四位数)
    • h 小时,12 小时格式,有前导零 01 到 12
      H 小时,24 小时格式,有前导零 00 到 23
      i 有前导零的分钟数 00 到 59>
      s 秒数,有前导零 00 到 59>

    在使用日期前一般要设置

    date_default_timezone_set(时区)

    中国为RPC。

    date_default_timezone_set('PRC');
    echo date('Y-m-d h:i:s' );

    输出:2013-10-15 10:04:12。

    int strtotime ( string $time [, int $now = time() ] )

    将任何英文文本的日期时间描述解析为 Unix 时间戳

    echo strtotime("now"), "
    ";
    echo strtotime("10 September 2000"), "
    ";
    echo strtotime("+1 day"), "
    ";
    echo strtotime("+1 week"), "
    ";
    echo strtotime("+1 week 2 days 4 hours 2 seconds"), "
    ";
    echo strtotime("next Thursday"), "
    ";
    echo strtotime("last Monday"), "
    ";

    判断前一天后一天的代码:

    date_default_timezone_set('PRC'); //默认时区     
    echo "今天:",date("Y-m-d",time()),"<br>";     
    echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";     
    echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>";     
    echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>";     
    echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>";     
    echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>";     
    echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>";     
    echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";     
    echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";     
    echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";     
    echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";

    判断某个日期离今天还有多少天:

    echo (strtotime('2013-10-17')-strtotime(date('Y-m-d')) )/86400;
  • 相关阅读:
    oracle 按关键字排序前几行
    oracle 查看某表的前10行
    linux 7安装部署Redis
    oracle 查看库表状态
    centos 7 启动和关闭zabbix 服务
    oracle 创建用户密码及赋予登录权限
    linux 控制root登录宿主机时间
    centos 更改用户登录宿主机时间
    oracle 查询、创建、删除 数据库用户
    Django基础四之模板系统
  • 原文地址:https://www.cnblogs.com/youxin/p/3369708.html
Copyright © 2020-2023  润新知