• PHP 格式化显示时间 date() 函数【转】


    date() 函数

      功能:用于格式化时间,返回一个字符串。 
      语法:string date( string format [, int timestamp] ),其中参数 format 表示时间格式化的方式;可选参数timestamp表示时间戳,默认为time(),即当前时间。

    时间格式化的方式

    格式化方式 说明
    Y 4位数字年,y为2位数字,如99即1999年
    m 数字月份,前面有前导0,如01。n 为无前导0数字月份
    F 月份,完整的文本格式,例如 January 或者 March
    M 三个字母缩写表示的月份,例如 Jan 或者 Mar
    d 月份中的第几天,前面有前导0,如03。j 为无前导0的天数
    w 星期中的第几天,以数字表示,0表示星期天
    z 年份中的第几天,范围0-366
    W 年份中的第几周,如第32周
    H 24小时格式,有前导0,h为12小时格式
    G 24小时格式,无前导0,g为对应12小时格式
    i 分钟格式,有前导0
    s 秒格式,有前导0
    A 大写上下午,如AM,a为小写

    例子一

    date("Y-m-d");               //显示格式如 2008-12-01
    date("Y-m-d",time());       //显示格式如 2008-12-01
    date("Y.m.d",time());       //显示格式如 2008.12.01
    date("M d Y",time());       //显示格式如 Dec 01 2008
    date("Y-m-d H:i",time());   //显示格式如 2008-12-01 12:01
    

    例子二

    <?php
    $date=date_create("2016-09-25");
    echo date_format($date,"Y/m/d H:i:s");
    ?>
    
    1. date_default_timezone_set('PRC');
    2. $start_time ="2017-3-22 17:00:00";//开始考试时间
    3. echo $start_time."";
    4. $mm =60*60;//PHP的时间是按秒算的
    5. echo date("Y-m-d H:i:s",strtotime($start_time)+$mm);

    如果输出的时间和实际时间差8个小时(假设采用的北京时区)的话,检查php.ini文件,做如下设置:date.timezone = PRC

    [参考] http://www.5idev.com/p-php_time_date.shtml

  • 相关阅读:
    LeetCode 301. Remove Invalid Parentheses
    LeetCode 126. Word Ladder II
    LeetCode 44. Wildcard Matching
    LeetCode 10. Regular Expression Matching
    LeetCode 65. Valid Number
    LeetCode 149. Max Points on a Line
    LeetCode 68. Text Justification
    LeetCode 212. Word Search II
    LeetCode 79. Word Search
    LeetCode 218. The Skyline Problem
  • 原文地址:https://www.cnblogs.com/KillBugMe/p/11805129.html
Copyright © 2020-2023  润新知