PHP strtotime()函数可以接受格式吗? [英] PHP strtotime() function that accepts a format?

查看:122
本文介绍了PHP strtotime()函数可以接受格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strtotime()的日期格式,它可以理解并可以转换,则可以很好地工作,但是例如,您给它指定了英国日期,则它无法提供正确的unix时间戳.

strtotime() in PHP works great if you can provide it with a date format it understands and can convert, but for example you give it a UK date it fails to give the correct unix timestamp.

是否有任何PHP函数(正式的或非正式的)可以接受格式变量,该变量告诉函数日期和时间以哪种格式传递?

Is there any PHP function, official or unofficial, that can accept a format variable that tells the function in which format the date and time is being passed?

与之最接近的是date_parse_from_format()mktime()

// Example usage of the function I'm after
//Like the date() function but in reverse
$timestamp = strtotimeformat("03/05/2011 16:33:00", "d/m/Y H:i:s");

推荐答案

如果您使用的是PHP 5.3:

If you have PHP 5.3:

$date = DateTime::createFromFormat('d/m/Y H:i:s', '03/05/2011 16:33:00');
echo $date->getTimestamp();

这篇关于PHP strtotime()函数可以接受格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆