I have an array :
$multiple_dates[0] = 2013-06-09 00:00:00;
$multiple_dates[1] = 2014-06-13 12:23:00;
Here is my code :
$format = "d-m-Y h:m:s";
for ($i = 0; $i < count($multiple_dates); $i++) {
$date_display = date_format(date_create($multiple_dates[$i]), $format);
$fdate = date_translate($format, $date_display);
echo $fdate;
}
But output is :
09-06-2013 12:06:00
13-06-2014 12:06:00
Time is not correct...Any idea ?
That's because minutes fraction is i
, not m
(which is month)
So
$format = "Y-m-d H:i:s";
Your format is invalid. Try with:
$format = "d-m-Y h:i:s";
It should be "i" like this
$format = "d-m-Y h:i:s";
edit like this you can get it
正确的格式是
$format = "d-m-Y H:i:s";
Check this code --
<?php
$mydate = '2014-06-13 12:23:00';
$format = "d-m-Y h:i:s";
echo $date_display = date_format(date_create($mydate), $format);
go for $timestamp = strtotime("09-06-2013 12:06:00")
and set on date('dmY h:m:s', $timestamp);
for ($i = 0; $i < count($multiple_dates); $i++) {
$timestamp = strtotime($multiple_dates[$i]));
$fdate=date('d-m-Y h:m:s', $timestamp);
echo $fdate;
}
You can just use strtotime
. Eg:
foreach ($multiple_dates as $date) {
echo date($format, strtotime($date));
}
tryin this one is easier....
for ($i = 0; $i < count($multiple_dates); $i++) {
echo date('d-m-Y H:i:s',strtotime($multiple_dates[$i]));
}
i would prefer this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.