php中设置本地时间 - web开发 - PHP时区 - Fantasy
首页 > web开发 > php中设置本地时间

php中设置本地时间

1.修改php.ini。打开php.ini查找date.timezone时间区去掉前面的分号
= 后面加XXX,重启服务器。例子 date.timezone = “PRC”

2.使用设置函数

date_default_timezone_set(‘PRC’);

用echo date(‘Y-m-d H:i:s’);

测试一下

PRC还可以改为:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)

我在运用中 出现了一个问题 就是无论怎么改 在我的页面里 插入数据库的时间都改不过来 ,时区依然不对。很晕。终于发现了 是我在插入数据库的时候 用了NOW()数据库函数 ,估计是它认的是数据库的时间。发显了这个问题,我把插入数据库的时间用

date_default_timezone_set(‘PRC’);  //先改下PHP默认时区
 $showtime=date(“Y-m-d H:i:s”); //获取当前时间赋值给$showtime

在插入数据库时 插入$showtime 解决了 。OK

  1. Livrare Flori 2月 26th, 2011 @ 18:39 | #-49

    I grew to dance and weave in the breeze, testing the strength I was recently discovering.

  2. Chinese Green Tea 5月 23rd, 2011 @ 21:41 | #-48

    Great blog , thanks for the post!

  3. soft tip darts 5月 24th, 2011 @ 03:35 | #-47

    I’m adding your blog rss feed so that I can see your new posts. Keep up the good work!

  4. x ray technician certification 6月 7th, 2011 @ 15:36 | #-46

    I am constantly searching online for articles that can aid me. Thank you!

评论提交中, 请稍候...

留言

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks
watch glee episodes joomla themes Wordpress主题站 templates2joomla