PHP:将YYYY-MMM-DD转换为YYYY-MM-DD

问题描述 投票:-2回答:7

我需要将日期字符串转换为数字:

2012-Sep-01 to 2012-09-01

有什么想法吗?问候,

php string date converter
7个回答
5
投票

尝试使用DateTime PHP类:

$date = "2012-Sep-01";
$result = DateTime::createFromFormat("Y-M-d", $date)->format("Y-m-d");

4
投票

使用strtotime()

echo date('Y-m-d', strtotime('2012-Sep-01'));

4
投票

这可能对您有用:

echo date("Y-m-d", strtotime($yourCurrentDateVat))'

PHP网站目前已关闭,但日期功能为here is some extra info


3
投票
$date = DateTime::createFromFormat('Y-M-j', '2012-Sep-01');
echo $date->format('Y-m-d');

实际上从手册中被盗:http://us.php.net/manual/en/datetime.createfromformat.php


1
投票

您应使用strtotime()。有关here的更多信息。然后date()创建一个新字符串。有关该here的更多信息。

$date = '2012-Sep-01'; //Sets your date string
$time_epoch = strtotime($date); //Converts the string into an epoch time
$new_date = date('Y-m-d', $time_epoch); //Creates a new string

1
投票
$timestamp = strtotime('22-09-2008');
$new_date = date("y-m-d", $timestamp);

0
投票

[嗨,尝试在PHP中使用它,您肯定会得到想要的东西,我一直在搜索相同的东西,但是没有找到,但是后来发现我在某处使用了日期时间公式,并对其进行了修改以得到它。

$getdatetime=date_create('2020-May-21'); $dateconverted=date_format($getdatetime,'Y-m-d'); echo $dateconverted;

© www.soinside.com 2019 - 2024. All rights reserved.