PHP是否具有date()函数的逆(除了strtotime())? [英] Does PHP have an inverse of the date() function (other than strtotime())?

查看:103
本文介绍了PHP是否具有date()函数的逆(除了strtotime())?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有使用 date()格式来解释字符串的功能?

Is there a function that uses the date() format to interpret a string?

echo date('s-i-H d:m:Y', 1304591364); // 34-29-17 05:05:2011

// Does this function exist?
echo inverse_date('s-i-H d:m:Y', '34-29-17 05:05:2011'); // 1304591364

我知道 strtotime() ,但是在大多数情况下,我并没有解析英文日期格式。

I know strtotime(), but it’s failing me in most cases as I am not parsing English date formats.

我正在寻找一个可以规定格式的函数。

I’m looking for a function that can dictate the format.

推荐答案

这个问题的真正答案是我的意思是
http://www.php.net/manual/en/datetime.createfromformat.php

The real answer to this question the way I mean it is http://www.php.net/manual/en/datetime.createfromformat.php

<?php
$date = date_create_from_format('j-M-Y', '15-Feb-2009');
echo date_format($date, 'Y-m-d'); // 2009-02-15
?>

这篇关于PHP是否具有date()函数的逆(除了strtotime())?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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