将日期转换为unixtime php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1670797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert date to unixtime php
提问by mrpatg
I have a form which posts date information month, day, yeah, hour, minute, am/pm. How do i encode/decode this to and from unixtime using php?
我有一个表格,它发布日期信息月、日、是、小时、分钟、上午/下午。我如何使用 php 在 unixtime 和 unixtime 之间进行编码/解码?
回答by Micha? Rudnicki
mktime()- Get Unix timestamp for a date
mktime()- 获取日期的 Unix 时间戳
echo mktime(23, 24, 0, 11, 3, 2009);
1257290640
To handle AM/PM just add 12 to hours if PM.
要处理 AM/PM,只需将 12 小时添加到 PM。
mktime($isAM ? $hrs : ($hrs + 12), $mins, $secs, $m, $d, $y);
Alternatively you could use strtotime():
或者,您可以使用 strtotime():
strtotime()- Parse about any English textual datetime description into a Unix timestamp
strtotime()- 将任何英文文本日期时间描述解析为 Unix 时间戳
echo strtotime("2009-11-03 11:24:00PM");
1257290640

