php中如何输出带中文的日期格式(年月日时分秒)

WBOY
Freigeben: 2016-08-08 09:33:17
Original
2980 Leute haben es durchsucht

php中如何输出带中文的日期格式(年月日时分秒)

代码如下:
function today(){
date_default_timezone_set ("Asia/Chongqing");
$a=date("Y");
$b=date("m");
$c=date("d");
$d=date("G");
$e=date("i");
$f=date("s");
return $a.'年'.$b.'月'.$c.'日'.$d.'时'.$e.'分'.$f.'秒';}

如果出现echo date("Y-m-d");

警号:

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting 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 in G:sourcetestceshimktime.php on line 4
网上查了下资料才知道原因,下面给大家分享下:
在用PHP5.3以上的PHP版本时,只要是涉及时间的会报一个

"PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting 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 in

以下是三种方法(任选一种都行):

一、在页头使用date_default_timezone_set()设置 date_default_timezone_set('PRC'); //东八时区 echo date('Y-m-d H:i:s');

二、在页头使用 ini_set('date.timezone','Asia/Shanghai');

三、修改php.ini。打开php5.ini查找date.timezone 去掉前面的分号修改成为:date.timezone =PRC
(www.111cn.net)
重启http服务(如apache2或iis等)即可。

关于date函数参数

d 月份中的第几天,有前导零的 2 位数字 01 到 31

D 星期中的第几天,文本表示,3 个字母 Mon 到 Sun

j 月份中的第几天,没有前导零 1 到 31

l (“L”的小写字母) 星期几,完整的文本格式 Sunday 到 Saturday

N ISO-8601 格式数字表示的星期中的第几天(PHP 5.1.0 新加) 1(星期一)到 7(星期天)

S 每月天数后面的英文后缀,2 个字符 st,nd,rd 或者 th。可以和 j 一起用

w 星期中的第几天,数字表示 0(星期天)到 6(星期六)

z 年份中的第几天 0 到 366

W ISO-8601 格式年份中的第几周,每周从星期一开始(PHP 4.1.0 新加的) 42(当年的第 42 周)

F 月份,完整的文本格式,例如 January 或者 March January 到 December

m 数字表示的月份,有前导零 01 到 12

M 三个字母缩写表示的月份 Jan 到 Dec

n 数字表示的月份,没有前导零 1 到 12

t 给定月份所应有的天数 28 到 31

L 是否为闰年 如果是闰年为 1,否则为 0

o ISO-8601 格式年份数字。

Y 4 位数字完整表示的年份 例如:1999 或 2003

y 2 位数字表示的年份 例如:99 或 03

a 小写的上午和下午值 am 或 pm

A 大写的上午和下午值 AM 或 PM

B Swatch Internet 标准时 000 到 999

g 小时,12 小时格式,没有前导零 1 到 12

G 小时,24 小时格式,没有前导零 0 到 23

h 小时,12 小时格式,有前导零 01 到 12

H 小时,24 小时格式,有前导零 00 到 23

i 有前导零的分钟数 00 到 59>

s 秒数,有前导零 00 到 59>

e 时区标识(PHP 5.1.0 新加) 例如:UTC,GMT,Atlantic/Azores

I 是否为夏令时 如果是夏令时为 1,否则为 0

O 与格林威治时间相差的小时数 例如:+0200

P 与格林威治时间(GMT)的差别,小时和分钟之间有冒号分隔 例如:+02:00

T 本机所在的时区

Z 时差偏移量的秒数。UTC 西边的时区偏移量总是负的,UTC 东边是正的。 -43200 到 43200

c ISO 8601 格式的日期(PHP 5 新加) 2004-02-12T15:19:21+00:00

r RFC 822 格式的日期 例如:Thu, 21 Dec 2000 16:01:07 +0200

U 从 Unix 纪元(January 1 1970 00:00:00 GMT)开始至今的秒数 time()获得时间戳

php的date()函数十分强大,通过上面这些参数可以实现很多日期的操作,比如说获取上面我标记的红色参数说明来实现今天是星期几操作!

以上就介绍了php中如何输出带中文的日期格式(年月日时分秒),包括了php日期格式方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!