如何php转换这个时间格式? [英] how to php convert this time format?
本文介绍了如何php转换这个时间格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从这个格式的数据库表中获取了这个日期
i was fetching this date from table in the database like this format
Sunday 16th of January 2011 06:55:41 PM
我想将其转换为这种格式
and i want to convert it to be like this format
11-05-2012
使用日期功能
使用日期功能或任何功能执行此操作
when i use date function
<td><?php echo date('d-m-Y', $v['v_created']); ?></td>
我收到错误讯息
'Severity: Warning
Message: date() expects parameter 2 to be long, string given'
推荐答案
这适用于我(仅在本地Web服务器上测试)
This works for me (just tested on local web server)
<?php
date_default_timezone_set ('Europe/Rome');
$date = "Sunday 16th of January 2011 06:55:41 PM";
//.Strip "of" messing with php strtotime
$date = str_replace('of', '', $date);
$sql_friendly_date = date('y-m-d H:i', strtotime($date));
echo $sql_friendly_date;
?>
您可以格式化日期,因为您喜欢根据以下更改Date功能的第一个参数: http://it2.php.net/manual/en/function.date.php
You can format the date as you prefer changing the first parameter of Date function according to: http://it2.php.net/manual/en/function.date.php
这篇关于如何php转换这个时间格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文