PHP获取本地时间
使用date ( "Y-m-d H:i:s" )函数获取当前时间,总是不对,原来默认是格林威治时间,解决的办法有两个:
1.获取之前先加 date_default_timezone_set("PRC");
//设置默认当前时区
date_default_timezone_set("PRC"); echo date ( "Y-m-d H:i:s" );
效果:

这种办法的局限是显而易见的,只对当前脚本起作用
2.想要一劳永逸的解决,其实也很简单,打开php.ini文件,找到 ;date.timezone = ,去掉注释,改为
date.timezone = "PRC"
重启apache即可
PHP获取本地时间的更多相关文章
- linux c获取本地时间
在标准C/C++中,我们可通过tm结构来获得日期和时间,tm结构在time.h中的定义如下: #ifndef _TM_DEFINED struct tm { int tm_sec; /* 秒–取值区间 ...
- C/C++获取本地时间常见方法
跨平台方法 方法一:手动暴力法 #include <iostream> using namespace std; #include <time.h> time_t t = ti ...
- iOS获取本地时间
NSDate *currentDate = [NSDate date];//获取当前时间,日期 NSDateFormatter *dateFormatter = [[NSDateFormatter a ...
- 利用JS获取本地时间和服务器时间
<p id="labTime"> <script type="text/javascript"> //取客户端时间 setInterva ...
- python获取本地时间
python本地时间 import time # 格式化成2016-03-20 11:45:39形式 now = time.strftime("%Y-%m-%d %H:%M:%S" ...
- JavaScript—获取本地时间以12小时制显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python获取本地时间,时间戳与日期格式相互转换
附上代码与运行结果截图: import time # 获取当前时间 now = time.localtime() # 格式化日期 now_ = time.strftime('%Y-%m-%d %H:% ...
- Python实例讲解 -- 获取本地时间日期(日期计算)
1. 显示当前日期: print time.strftime('%Y-%m-%d %A %X %Z',time.localtime(time.time())) 或者 你也可以用: print list ...
- objectiveC获取本地时间。
NSDate * date = [NSCalendarDate date]; NSLog(@"%@", date); 日历在IOS里报错,,. NSDateFormatter *f ...
随机推荐
- 最新版IntelliJ IDEA2019.1破解教程(2019.04.08更新)
[原文链接]:https://www.tecchen.xyz/idea-crack.html 我的个人博客:https://www.tecchen.xyz,博文同步发布到博客园. 由于精力有限,对文章 ...
- windows phpinfo上不能找到memcache扩展 php版本5.6
我的memcache用的我是memcached-win64-1.4.4-14.zip这个版本memcache扩展库下载地址:http://windows.php.net/downloads/pecl/ ...
- 解决flex布局下, elementui table组件不能跟随父组件的宽度而变化的bug
bug: 我在flex布局的元素中使用了elementui的table组件,饿了么的table上会被加一个动态的宽度, 当第一次改变flex元素宽度的时候.table的动态宽度会变化,第二次和以后就不 ...
- Sweep Line
391. Number of Airplanes in the Sky https://www.lintcode.com/problem/number-of-airplanes-in-the-sky/ ...
- eclipse中提示js或者JQuery代码
当你在eclipse中的JSP中写JavaScript或者JQuery代码的时候,eclipse是不会自动提示的,所以你需要在eclipse中安装一下插件,该插件的名字叫:Spket IDE,它可以作 ...
- cors允许的方法和contype-type
https://fetch.spec.whatwg.org/#cors-safelisted-request-header get head post text/plain multipart/for ...
- WPF中用后台C#代码为TabItem设置Background属性
TabItem tabItem = sender as TabItem; tabItem.Background = new ImageBrush(new BitmapImage(new Uri(@&q ...
- memcached 学习笔记 5
memcached installed on linux 使用的操作系统是centos6.5 (有桌面) 1 上传libebent和memcache到/usr/local/src [root@jt ...
- 深入redis内部--实现双向链表
数据结构的应用--Adlist.h定义 1.节点结构 typedef struct listNode { struct listNode *prev; //前向节点 struct lis ...
- 把AspDotNetCoreMvc程序运行在Docker上-part1
接<基于ASP.Net Core学习Docker技术第一步:在CentOS7安装Docker平台>这个博文,在搭建完成Docker平台之后,可以开始让aspdotnetcore程序运行在d ...