PHP 日期函数:strftime用法

trftime (PHP 4, PHP 5) : 根据locale的设定,来格式化日期和时间。

 

一、方法说明

 

string strftime ( string $format [, int $timestamp = time() ] )

 

其中:$format : 为日期格式.

         $timestamp : 时间戳.(可选)

 

二、使用中的问题:

2.1 locale如何设定:locale设定方式有两种,二者选择其一就好(建议通过php.ini来设定)

 

  • 将php.ini中的参数,设定为date.timezone参数为合适locale数据值。例如:Asia/Shanghai为上海
  • 在呼叫strftime( )之前,先使用date_default_timezone_set( )来设定locale
  • 如果没有设定locale,直接呼叫strftime()格式化日期时间,则系统会报如下错误信息。
strftime() [<a href='function.strftime'>function.strftime</a>]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead

 

2.2 $format的设定

详细的设定写法请参考http://php.net/manual/en/function.strftime.php。这里有详细的说明方式。下面举例一些常用的写法

格式          备注
strftime("%Y-%m-%d")输出:2012-12-02
strftime("%Y-%m-%d %H:%M:%S")输出:2012-12-02 18:29:00
strftime("%c")

以locale prefered的方式格式化日期时间。

例如当locale设定为Asia/Shanghai的时候,输出的数据为:12/02/12 18:40:33

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值