注意:我从我的Excel中检索了$ dateString
$dateString = "29/07/2008 7:51:00 PM";
$timestamp = date('Y-m-d h:i a', strtotime(str_replace('/','-', $dateString)));
echo $timestamp;
我得到的输出 2029-07-08 12:00 am
但是我需要这样的输出。请帮助我
2008-07-29 7:51:00
答案 0 :(得分:0)
使用H:i:s
代替h:i a
。您的代码应该是这样的
$dateString = "29/07/2008 7:51:00 PM";
$timestamp = date('Y-m-d H:i:s', strtotime(str_replace('/','-',
$dateString)));
echo $timestamp;
答案 1 :(得分:0)
您需要删除' a'摆脱AM / PM
你需要一个' H'而不是' h'下午7:14改为19:14
$timestamp = date('Y-m-d H:i:s ', strtotime(str_replace('/','-', $dateString)));
答案 2 :(得分:0)
在没有前导零的情况下使用Started PUT "/auth/password/" for ::1 at 2018-03-20 11:06:28 +0545
Processing by DeviseTokenAuth::PasswordsController#update as */*
User Load (1.6ms) SELECT "users".* FROM "users" WHERE "users"."uid" = $1 LIMIT $2 [["uid", "manager2@gmail.com"], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."uid" = $1 LIMIT $2 [["uid", "manager2@gmail.com"], ["LIMIT", 1]]
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.12ms)
Completed 401 Unauthorized in 7ms (Views: 1.6ms | ActiveRecord: 1.7ms)
小时
g
答案 3 :(得分:0)
如果您使用的是laravel,请尝试Carbon
$datetime = DateTime::createFromFormat("Y-m-d h:i:s", $dateString);
$timestamp = $datetime->getTimestamp();
或者你也应该试试这个
list($day,$month,$year, $hour, $minute, $dayType) = preg_split('/[\/\s:]+/', $dateString);
echo $date = $year . '-' . $month. '-' . $day . ' ' . ($dayType == "PM"?$hour+12: $hour) . ":" . $minute . ":00";
答案 4 :(得分:0)
你应该试试这个:
$date = "29/07/2008 7:51:00 PM";
$date = str_replace('/', '-', $date);
echo date('Y-m-d h:i:s', strtotime($date));
答案 5 :(得分:0)
尝试IT .....
$dateString = "29/07/2008 7:51:00 PM";
$timestamp = date('Y-m-d h:i:s', strtotime(str_replace('/','-', $dateString)));
echo $timestamp;
输出:2008-07-29 07:51:00