且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将日期转换为unixtime php

更新时间:2023-11-29 12:15:40

mktime() - 获取日期的Unix时间戳

mktime() - Get Unix timestamp for a date

echo mktime(23, 24, 0, 11, 3, 2009);
1257290640

处理AM / PM只需添加12到小时如果PM。

To handle AM/PM just add 12 to hours if PM.

mktime($isAM ? $hrs : ($hrs + 12), $mins, $secs, $m, $d, $y);

或者您可以使用strtotime():

Alternatively you could use strtotime():

strtotime() - 将有关任何英文文本datetime描述解析为Unix时间戳记

strtotime() - Parse about any English textual datetime description into a Unix timestamp

echo strtotime("2009-11-03 11:24:00PM"); 
1257290640