日期格式 PHP 但完整的月份名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7998715/
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
Date formatting PHP but full month name
提问by Darren Sweeney
I need this:
我需要这个:
12 November, 1997
to be reformatted to:
重新格式化为:
1997-11-12
for inclusion in MySQL database, but I'm struggling with the full month name, is this possible?
包含在 MySQL 数据库中,但我正在为完整的月份名称而苦苦挣扎,这可能吗?
Thanks
谢谢
Darren
达伦
采纳答案by Niet the Dark Absol
date("Y-m-d",strtotime("12 November, 1997"));
Returns 1997-11-12
, exactly what you need :)
返回1997-11-12
,正是您所需要的 :)
回答by mukesh kumar
$tempDate = '2013-06-09';
$day = date('l', strtotime( $tempDate));// will gives you the week day name
$month = date('jS F Y',strtotime($tempDate));// will format like date 9th June 2013
回答by kidata
This should work for you:
这应该适合你:
date("Y-m-d", strtotime(12 November, 1997));
回答by nickb
You can use DateTime::createFromFormat, if you have PHP >= 5.3
你可以使用DateTime::createFromFormat,如果你有 PHP >= 5.3
回答by Marc B
Hacky method:
哈克方法:
$timestamp = strtotime('12 November, 1997');
$sql = "INSERT INTO table (datefield) VALUES (FROM_UNIXTIME($timestamp))";
Somewhat less hacky:
不那么hacky:
$timestamp = DateTime::CreateFromFormat('j F, Y', '12 November, 1997')->format('U');
$sql = "same as above";