php 将日期转换为 UNIX 时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11324195/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:16:55  来源:igfitidea点击:

Convert Date to UNIX timestamp

phpunixdatetimestamp

提问by user1425322

I'm having a date format of Jun 26, '12.
strtotime()converts proper date string, and this string results in a blank output. This can be solved but I can only think of ugly ways of doing it.

我的日期格式为Jun 26, '12.
strtotime()转换正确的日期字符串,此字符串导致空白输出。这可以解决,但我只能想到丑陋的方法。

Any ideas for converting this date format to UNIX timestamp elegantly?

有什么想法可以优雅地将此日期格式转换为 UNIX 时间戳?

回答by user850234

How about this strtotime('Jun 26,12');

这个怎么样 strtotime('Jun 26,12');

回答by vikramaditya234

I used DateTime::createFromFormatworks well for me.. more info here.

我用过DateTime::createFromFormat对我来说效果很好..更多信息在这里

回答by Charlie Martin

Um, s/'/20/g'? Followed by strtotime()?

嗯,s/'/20/g'?其次是strtotime()

回答by Stano

Maybe something like this?

也许是这样的?

$string = 'April 26,\'12';
echo strtotime(preg_replace('/(\w+) (\d+),\'(\d+)/i', '  20', $string));

Based on example from php.net

基于来自php.net 的示例