• (九)Date&Time——PHP


    第九章 Date & Time

    1 time()获取时间戳

    time()函数返回的整数表示自1970年1月1日格林尼治标准时间午夜起经过的秒数。这一时刻称为UNIX历元,自那时起经过的秒钟数称为时间戳

     
    	print time()
     ?>
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    2 getDate()转换时间戳

    **函数getdate()可选地接受一个时间戳,并返回一个包含日期信息的关联数组。如果省略时间戳,它将使用time()**返回的当前时间戳。

    下表列出了**getdate()**返回的数组中包含的元素。

    Sr.NoKey & DescriptionExample
    1seconds 一分钟的秒数 (0-59)20
    2minutes 一小时的分钟数(0 - 59)29
    3hours 一天中的小时数(0 - 23)22
    4mday 每月的第几天 (1 - 31)11
    5wday 星期几(0 - 6)4
    6mon 一年中的月份 (1 - 12)7
    7year 年份(四位数)1997
    8yday 一年中的第几天( 0 - 365 )19
    9weekday 一周中的哪一天Thursday
    10month 一年中的月份January
    110 时间戳948370048
     
    	$date_array = getdate();
    	foreach ($date_array as $key => $value) {
    		echo $key." = ".$value."
    "
    ; } $today = "
    Today's date:"
    ; $today .= $date_array['mday']."/"; $today .= $date_array['mon']."/"; $today .= $date_array['year']; echo $today; ?>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    在这里插入图片描述

    3 date()转换时间戳

    date()函数返回表示日期的格式化字符串,该格式带有必须传递给它的字符串参数。

    格式:

    date(format, timestamp)
    
    • 1

    **date()可选地接受时间戳,如果省略,则将使用当前日期和时间。传递给date()**的格式字符串中包含的任何其他数据都将包含在返回值中

    下表列出了格式字符串可以包含的代码:

    Sr.NoFormat & DescriptionExample
    1a ‘am’ or ‘pm’ lowercasepm
    2A ‘AM’ or ‘PM’ uppercasePM
    3**d ** Day of month, a number with leading zeroes20
    4**D ** Day of week (three letters)Thu
    5F Month nameJanuary
    6h Hour (12-hour format - leading zeroes)12
    7H Hour (24-hour format - leading zeroes)22
    8g Hour (12-hour format - no leading zeroes)12
    9G Hour (24-hour format - no leading zeroes)22
    10i Minutes ( 0 - 59 )23
    11j Day of the month (no leading zeroes20
    12l (Lower ‘L’) Day of the weekThursday
    13L Leap year (‘1’ for yes, ‘0’ for no)1
    14**m ** Month of year (number - leading zeroes)1
    15M Month of year (three letters)Jan
    16**r ** The RFC 2822 formatted dateThu, 21 Dec 2000 16:01:07 +0200
    17**n ** Month of year (number - no leading zeroes)2
    18**s ** Seconds of hour20
    19U Time stamp948372444
    20y Year (two digits)06
    21Y Year (four digits)2006
    22**z ** Day of year (0 - 365)206
    23**Z ** Offset in seconds from GMT+5
    
       echo "Today:";
       $date = date("Y-m-d H:i:s A");
       print($date);
    ?>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

  • 相关阅读:
    什么?Coolbpf 不仅可以远程编译,还可以发现网络抖动!
    第43期:多表关联场景下如何用好分区表
    SpringBoot3.0正式发布,我来尝尝鲜
    78 # koa 中间件的实现
    rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp)
    凭着这份《微服务架构实战》,带你立足实战落地微服务架构
    JavaScript获取DOM元素相关信息和属性
    深入理解Kafka核心设计及原理(四):主题管理
    网络资料(忘传了)
    DGL学习笔记——第二章 消息传递范式
  • 原文地址:https://blog.csdn.net/Mr_Morgans/article/details/127919725