惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
博客园 - 【当耐特】
F
Fortinet All Blogs
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
Google DeepMind News
Google DeepMind News
博客园_首页
A
About on SuperTechFans
博客园 - 聂微东
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
GbyAI
GbyAI
O
OpenAI News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
J
Java Code Geeks
T
Tor Project blog
T
Threatpost
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
D
Docker
Vercel News
Vercel News
I
Intezer
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
U
Unit 42
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 涂文瀚

常用的前端调试工具 用户中心 - 博客园 SQL中动态进行行转列 SQL SERVER 表分区实施步奏 [记录]SQL SERVER 跨库操作小记 PHP常见面试问题 在WIN下搭建PHP的测试、开发环境 [转]三款免费的PHP加速器:APC eAccelerator XCache比较 Xdebug如何选择PHP版本 PHP Cookbook读书笔记 – 第01章字符串 PHP Cookbook读书笔记 – 第02章数字 PHP Cookbook读书笔记 – 第04章数组 PHP Cookbook读书笔记 – 第06章函数 PHP Cookbook读书笔记 – 第07章类和对象 PHP Cookbook读书笔记 – 第08章web基础 设计模式之观察者模式 PHP Cookbook读书笔记 – 第09章表单 PHP Cookbook读书笔记 – 第11章Session和持久化 PHP Cookbook读书笔记 – 第12章XML
PHP Cookbook读书笔记 – 第03章日期和时间
涂文瀚 · 2011-12-15 · via 博客园 - 涂文瀚

本章介绍了日期常用的函数及经常碰到的处理日期/时间的情景,如计算两个时间的差,还简单的介绍了不同时区间的日期显示问题。对于天文日历计算方面的(儒略日)转换函数,个人认为可以忽略。

strftime() : 根据区域设置setlocal()格式化时间/日期
date() :格式一个本地日期/时间
getdate() : 取得日期/时间(可以指定某时间戳)

Return array from getdate( )

Key

Value

seconds

Seconds

minutes

Minutes

hours

Hours

mday

Day of the month

wday

Day of the week, numeric (Sunday is 0, Saturday is 6)

mon

Month, numeric

year

Year, numeric (4 digits)

yday

Day of the year, numeric (e.g., 299)

weekday

Day of the week, textual, full (e.g., "Friday")

month

Month, textual, full (e.g., "January")

0

Seconds since epoch (what time( ) returns)

localtime() : 返回本地服务器的时间

Return array from localtime( )

Numeric position

Key

Value

0

tm_sec

Second

1

tm_min

Minutes

2

tm_hour

Hour

3

tm_mday

Day of the month

4

tm_mon

Month of the year (January is 0)

5

tm_year

Years since 1900

6

tm_wday

Day of the week (Sunday is 0)

7

tm_yday

Day of the year

8

tm_isdst

Is daylight savings time in effect?

mktime() : 取一个日期的unix时间戳,有6个参数时、分、秒、月、日、年
gmmktime() : 取GMT日期的unix时间戳
gregoriantojd() : 公历转儒略日(忽略)
checkdate() : 验证一个日期是否有效(例如可以判断4月31日为一错误日期)
date_default_timezone_set() : 设定用于脚本的默认时区
microtime() : 返回Unix时间戳和微秒数,用来计算程序的运行时间常用这个方法
cal_from_jd() : 转换Julian Day计数到一个支持的历法(忽略)
cal_to_jd() : 从一个支持的历法转变为Julian Day计数(忽略)
gregoriantojd() : 转变一个Gregorian历法日期到Julian Day计数(忽略)
Date_Calc () : pear的日历扩展类
putenv() : 配合localtime()通过设置一个时区的环境变量来获得当地时间(解决服务器和访问者不在同一个时区的情况)

<?php
$stamp_future = mktime(19,28,0,5,19,2011);
print strftime('%c',$stamp_future);	 
//输出:05/19/11 19:28:00

$a = getdate();
printf('%d-%d-%d %s:%s:%s',$a['year'],$a['mon'],$a['mday'],$a['hours'],$a['minutes'],$a['seconds']);
//输出:2011-5-19 11:32:18

// 7:32:56 pm on May 10, 1965
$epoch_1 = mktime(19,32,56,5,10,1965);
// 4:29:11 am on November 20, 1962
$epoch_2 = mktime(4,29,11,11,20,1962);
// 两个日期相差的秒数
$diff_seconds  = $epoch_1 - $epoch_2;
//相差的天数
$diff_days     = floor($diff_seconds/86400);

?>

儒略日(Julian day,JD)是指由公元前4713年1月1日,协调世界时中午12时开始所经过的天数,多为天文学家采用,用以作为天文学的单一历法,把不同历法的年表统一起来。如果计算相隔若干年两个日期之间的天数,利用儒略日就比较方便。