0

次の形式の文字列があります yyyy-mm-dd-hh-mm-ss

この形式になっているのは、URL の一部であるためです。PHPで使用可能な時間形式に変換するのに助けが必要です。

これが私がこれまでに試したことです。

$time = "2013-04-14-23-33-17";
$time2 = strtotime($time);
$time3 = date('M d, Y', $time2) . ' ' . _('at') . ' ' . date('h:i a', $time2);
echo $time3;

2013 年 4 月 14 日午後 11 時 33 分ではなく、1970 年 1 月 1 日午前 12 時 00 分にエコー アウトします。

4

2 に答える 2

3

It doesn't work because that's not a valid date format. See Supported Date and Time Formats.

What you need to do is create a DateTime object by specifing a format for your string.

DateTime::createFromFormat does exactly that.

于 2013-04-15T03:44:13.637 に答える
2

You could use DateTime to help you with the parsing:

$date = DateTime::createFromFormat('Y-m-d-H-i-s', $time);
echo $date->format('M d, Y h:i a');
于 2013-04-15T03:45:04.990 に答える