php关于时间函数大全
date函数
-
string date(string format[, int timestamp])
-
描述:格式化一个本地时间/日期
-
format格式:
-
Y:4位数字完整表示的年份
-
y:2位数字表示的年份
-
F:月份,完整的文本格式
-
M:三个字母缩写表示的月份
-
m:数字表示的月份,有前导零
-
n:数字表示的月份,没有前导零
-
d:月份中的第几天,有前导零
-
j:月份中的第几天,没有前导零
-
l:星期几,完整的文本格式
-
D:星期中的第几天,文本表示,3个字母
-
w:星期中的第几天,数字表示
-
H:小时,24小时格式,有前导零
-
i:有前导零的分钟数
-
s:秒数,有前导零
与时区相关的函数
- date_default_timezone_set函数
- bool date_default_timezone_set(string timezone_identifier)
- 描述:设置默认时区
- date_default_timezone_get函数
- string date_default_timezone_get()
- 描述:获取默认时区
time函数
-
int time()
-
描述:返回当前Unix时间戳
strtotime函数
- int strtotime(string $time[, int $now = time()])
- 描述:将字符串转换成Unix时间戳
以"天"为基础的格式
- yesterday 昨天午夜
- midnight 午夜
- today 今天
- noon 中午12:00:00
- tomorrow 明天午夜
- first day of ?? 某月第一天
- last day of ?? 某月最后一天
echo time(), “\n”; //当前的时间戳
echo strtotime(’-3 month’), “\n”; //获取之间的时间戳
echo microtime(true), “\n”;
生成唯一的ID
uniqid函数
string uniqid(string $prefix =""[, bool m o r e e n t r o p y = f a l s e ] ) 描 述 : 生 成 唯 一 I D , more_entropy = false]) 描述:生成唯一ID, moreentropy=false])描述:生成唯一ID,prefix是前缀
echo uniqid(), “\n”;
echo uniqid(time()), “\n”;
常见uuid生成方式
echo md5(uniqid(microtime() . mt_rand())), “\n”;