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-02strftime("%Y-%m-%d %H:%M:%S")输出:2012-12-02 18:29:00strftime("%c") 以locale prefered的方式格式化日期时间。
例如当locale设定为Asia/Shanghai的时候,输出的数据为:12/02/12 18:40:33
页:
[1]