strftime函数

2023-11-08 15:32
文章标签 函数 strftime

本文主要是介绍strftime函数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

strftime(format,timestamp)

 

Parameter参数Description描述
formatRequired. Specifies how to return the result:
必要参数。指定了返回结果的方法:
  • %a - abbreviated weekday name
    %a – 缩略的表示星期几的名称
  • %A - full weekday name
    %A – 表示星期几的全称
  • %b - abbreviated month name
    %b – 月份简称
  • %B - full month name
    %B – 月份全称
  • %c - preferred date and time representation
    %c – 首选的日期和时间表示法
  • %C - century number (the year divided by 100, range 00 to 99)
    %C – 表示世纪的数字(年份除以100,范围从00到99)
  • %d - day of the month (01 to 31)
    %d – 一个月包含的天数(从01到31)
  • %D - same as %m/%d/%y
    %D – 时间格式,与%m/%d/%y表示法相同
  • %e - day of the month (1 to 31)
    %e - 一个月包含的天数,数字前不包括0(从1到31)
  • %g - like %G, but without the century
    %g – 与%G雷同,但除去“世纪[century]”
  • %G - 4-digit year corresponding to the ISO week number (see %V).
    %G – 与ISO星期数相对应的4位数年份(见%V)
  • %h - same as %b
    %h – 与%b相同
  • %H - hour, using a 24-hour clock (00 to 23)
    %H – 小时,使用24小时时钟(00到23)
  • %I - hour, using a 12-hour clock (01 to 12)
    %I – 小时,使用12小时时钟(01到12)
  • %j - day of the year (001 to 366)
    %j – 一年的天数(001到366)
  • %m - month (01 to 12)
    %m – 月份(01到12)
  • %M - minute
    %M – 分钟
  • %n - newline character
    %n – 换行符
  • %p - either am or pm according to the given time value
    %p – 与给定的时间值相对应的am或pm
  • %r - time in a.m. and p.m. notation
    %r -用am或pm表示给定的时间
  • %R - time in 24 hour notation
    %R – 用24小时制表示的时间
  • %S - second
    %S – 秒
  • %t - tab character
    %t – tab键制表符
  • %T - current time, equal to %H:%M:%S
    %T – 当前时间,与“%H:%M:%S”组合相同
  • %u - weekday as a number (1 to 7), Monday=1. Warning: In Sun Solaris Sunday=1
    %u – 以数字形式表示星期几(1到7),Monday=1。提醒:在SUN Sloaris系统中,Sunday=1
  • %U - week number of the current year, starting with the first Sunday as the first day of the first week
    %U – 当今年份中包含的周的总数,以第一个星期日作为第一周的第一天
  • %V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week
    %V – 在当今年份中所包含的ISO 8601格式下的周的总数(01到53),week 1表示第一周,以周一作为每周的第一天
  • %W - week number of the current year, starting with the first Monday as the first day of the first week
    %W – 当前年份中包含的周的总数,以第一个星期一作为第一周的第一天
  • %w - day of the week as a decimal, Sunday=0
    %w – 以数字的形式表示星期几,Sunday[星期日]=0
  • %x - preferred date representation without the time
    %x – 选取除去时间[time]的日期[date]
  • %X - preferred time representation without the date
    %X –选取除去日期[date]的时间[time]
  • %y - year without a century (range 00 to 99)
    %y – 只显示包含年份的数字,不包含表示世纪的数字(00-99)
  • %Y - year including the century
    %Y – 显示包含世纪数字的年份(即:四位数字表示的年份,如:1999,2001等)
  • %Z or %z - time zone or name or abbreviation
    %Z或%z – 前者为时区名称;后者为时区名称的简称
  • %% - a literal % character
    %% - 输出“%”字符串
timestampOptional. Specifies the date or time to be formatted. If no timestamp is specified, it uses the current local time.
可选参数。指定日期或时间的格式。如果没有指定时间戳[timestamp],那么将默认使用当前的GMT时间。

 


Tips and Notes
提示

Tip: This function is identical to gmstrftime() except that the time returned is local time.
提示:strftime()函数与gmstrftime()函数大致相同,唯一的不同是strftime()函数传递的是本地时间。


Example
案例

Example of both strftime() and gmstrftime():
strftime() 和 gmstrftime()案例是:

<?php
echo(strftime("%b %d %Y %X", mktime(20,0,0,12,31,98))."<br />");
echo(gmstrftime("%b %d %Y %X", mktime(20,0,0,12,31,98))."<br />");
//Print the current date, time, and time zone.
echo(gmstrftime("It is %a on %b %d, %Y, %X time zone: %Z",time()));
?>

The output of the code above could be:
上述代码将输出下面的结果:

Dec 31 1998 20:00:00
Dec 31 1998 19:00:00
It is Wed on Jan 25, 2006, 11:32:10 time zone: W. Europe Standard Time

这篇关于strftime函数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/370819

相关文章

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

MySQL中FIND_IN_SET函数与INSTR函数用法解析

《MySQL中FIND_IN_SET函数与INSTR函数用法解析》:本文主要介绍MySQL中FIND_IN_SET函数与INSTR函数用法解析,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一... 目录一、功能定义与语法1、FIND_IN_SET函数2、INSTR函数二、本质区别对比三、实际场景案例分

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

C语言函数递归实际应用举例详解

《C语言函数递归实际应用举例详解》程序调用自身的编程技巧称为递归,递归做为一种算法在程序设计语言中广泛应用,:本文主要介绍C语言函数递归实际应用举例的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录前言一、递归的概念与思想二、递归的限制条件 三、递归的实际应用举例(一)求 n 的阶乘(二)顺序打印

C/C++错误信息处理的常见方法及函数

《C/C++错误信息处理的常见方法及函数》C/C++是两种广泛使用的编程语言,特别是在系统编程、嵌入式开发以及高性能计算领域,:本文主要介绍C/C++错误信息处理的常见方法及函数,文中通过代码介绍... 目录前言1. errno 和 perror()示例:2. strerror()示例:3. perror(

Kotlin 作用域函数apply、let、run、with、also使用指南

《Kotlin作用域函数apply、let、run、with、also使用指南》在Kotlin开发中,作用域函数(ScopeFunctions)是一组能让代码更简洁、更函数式的高阶函数,本文将... 目录一、引言:为什么需要作用域函数?二、作用域函China编程数详解1. apply:对象配置的 “流式构建器”最

Android Kotlin 高阶函数详解及其在协程中的应用小结

《AndroidKotlin高阶函数详解及其在协程中的应用小结》高阶函数是Kotlin中的一个重要特性,它能够将函数作为一等公民(First-ClassCitizen),使得代码更加简洁、灵活和可... 目录1. 引言2. 什么是高阶函数?3. 高阶函数的基础用法3.1 传递函数作为参数3.2 Lambda