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

推荐订阅源

V
Vulnerabilities – Threatpost
V
Visual Studio Blog
博客园_首页
Last Week in AI
Last Week in AI
J
Java Code Geeks
V
V2EX
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
Arctic Wolf
S
Security Affairs
博客园 - 聂微东
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
雷峰网
雷峰网
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
I
Intezer
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Engineering at Meta
Engineering at Meta
D
Docker
C
Check Point Blog
N
News | PayPal Newsroom
H
Hacker News: Front Page
T
The Blog of Author Tim Ferriss
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CXSECURITY Database RSS Feed - CXSecurity.com
SecWiki News
SecWiki News
The Last Watchdog
The Last Watchdog
Recorded Future
Recorded Future
量子位
NISL@THU
NISL@THU
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
MyScale Blog
MyScale Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
InfoQ
Hacker News: Ask HN
Hacker News: Ask HN

博客园 - 涂文瀚

常用的前端调试工具 用户中心 - 博客园 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时开始所经过的天数,多为天文学家采用,用以作为天文学的单一历法,把不同历法的年表统一起来。如果计算相隔若干年两个日期之间的天数,利用儒略日就比较方便。