php 5中的日期格式转换

时间:2016-01-07 14:47:58

标签: php

我想将D, d.m.y转换为Y-m-d格式,即

echo $from_date=date('Y-m-d', strtotime(Wed, 09.12.15));

但是这给了我这个结果2016-01-13

https://app.absence.io/#/calendar/absence/new 检查此链接,我想将2016-01-01格式的日期发送到数据库

4 个答案:

答案 0 :(得分:4)

首先,确保您的日期字符串包含在引号中("')。

其次,"周三,09.12.15"是 strtotime()可以理解的有效日期格式。

date formats is listed here的完整列表。

答案 1 :(得分:1)

您可以使用DateTime::createFromFormat()将非标准日期/时间字符串转换为DateTime对象,然后使用DateTime::format()以您首选格式创建日期/时间字符串。

例如:

<?php

$date = '09.12.15';

$dt = DateTime::createFromFormat('d.m.y', $date);

echo $dt->format('Y-m-d'); // 2015-12-09

希望这会有所帮助:)

答案 2 :(得分:0)

Source

$date1 = date('D d/m/Y h:i:s A',strtotime('2015-06-01'));

以下是您可以使用的格式列表(Source

Day of Month
____________
d   | Numeric, with leading zeros   01–31
j   | Numeric, without leading zeros    1–31
S   | The English suffix for the day of the month   st, nd or th in the 1st, 2nd or 15th.

Weekday
_______
l   | Full name  (lowercase 'L')    Sunday – Saturday
D   | Three letter name Mon – Sun

Month
______
m   | Numeric, with leading zeros   01–12
n   | Numeric, without leading zeros    1–12
F   | Textual full  January – December
M   | Textual three letters Jan - Dec

Year
____
Y   | Numeric, 4 digits Eg., 1999, 2003
y   | Numeric, 2 digits Eg., 99, 03

Time
____
a   | Lowercase am, pm
A   | Uppercase AM, PM
g   | Hour, 12-hour, without leading zeros  1–12
h   | Hour, 12-hour, with leading zeros 01–12
G   | Hour, 24-hour, without leading zeros  0-23
H   | Hour, 24-hour, with leading zeros 00-23
i   | Minutes, with leading zeros   00-59
s   | Seconds, with leading zeros   00-59
T   | Timezone abbreviation Eg., EST, MDT ...
Full Date/Time
c   | ISO 8601  2004-02-12T15:19:21+00:00
r   | RFC 2822  Thu, 21 Dec 2000 16:01:07 +0200

答案 3 :(得分:0)

愿这是工作

$dob = date("d/m/Y",strtotime('09-12-2015'));

 $dob = date("d/m/Y",strtotime($res[$i]['date_from_datebase]));

这将以d / m / Y格式从数据库输出日期。