PHP Cookbook读书笔记 – 第03章日期和时间
Jun 06, 2016 pm 07:40 PM本章介绍了 日期 常用的函数及经常碰到的处理 日期 / 时间 的情景,如计算两个 时间 的差,还简单的介绍了不同时区间的 日期 显示问题。对于天文日历计算方面的(儒略日)转换函数,个人认为可以忽略。 strftime() : 根据区域设置setlocal()格式化 时间 / 日
本章介绍了日期常用的函数及经常碰到的处理日期/时间的情景,如计算两个时间的差,还简单的介绍了不同时区间的日期显示问题。对于天文日历计算方面的(儒略日)转换函数,个人认为可以忽略。
strftime() : 根据区域设置setlocal()格式化时间/日期
date() :格式一个本地日期/时间
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() : 返回本地服务器的时间
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()通过设置一个时区的环境变量来获得当地时间(解决服务器和访问者不在同一个时区的情况)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
儒略日(Julian day,JD)是指由公元前4713年1月1日,协调世界时中午12时开始所经过的天数,多为天文学家采用,用以作为天文学的单一历法,把不同历法的年表统一起来。如果计算相隔若干年两个日期之间的天数,利用儒略日就比较方便。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
