PHP 将日期格式 Ymd 转换为 mdY

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14208743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:51:32  来源:igfitidea点击:

PHP Convert Date format Y-m-d to m-d-Y

php

提问by user1563221

I want to make my date format in Month-Date-Year. Current format is Year-Month-Date. How do I do that in PHP?

我想让我的日期格式为Month-Date-Year. 当前格式为Year-Month-Date. 我如何在 PHP 中做到这一点?

回答by underscore

$date = "08/01/2013";
$your_date = date("m-d-y", strtotime($date));

I hope my answer is useful :)

我希望我的回答有用:)

回答by Taz

$originalDate = "2013-01-08";
$newDate = date("m-d-Y", strtotime($originalDate));

回答by Taz

You can use strtotime()to parse the date. This literally took me one Google Searchto figure this out.

您可以使用strtotime()来解析日期。从字面上看,我花了一个谷歌搜索来弄清楚这一点。

$given = "2013-01-08";
$parseit = date("m-d-Y", strtotime($given));

And then you can echo it something like this:

然后你可以像这样回显它:

echo $parseit;

回答by OrangE

echo date('m-d-Y', time());

echo date('m-d-Y', time());

For more information see PHP's date documentation.

有关更多信息,请参阅PHP 的日期文档

回答by Sree

Try this.

尝试这个。

date('m-d-y', strtotime('2012-12-31'));

or

或者

$d = new DateTime('2012-12-31');

echo $d->format('m-d-y');

回答by Frank He

Refer to these two functions:

参考这两个函数:

For example (you need to update format)

例如(您需要更新格式)

$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y-m-d');

回答by DWright

You can use strtotime()to get your string back into a time variable. Then use date()to format the time to your required format.

您可以使用strtotime()将字符串恢复为时间变量。然后使用date()将时间格式化为您所需的格式。

回答by anuj arora

Just use

只需使用

date("m-d-Y");

This will output your in Month-Date-Year.

这将输出您的 in Month-Date-Year.

回答by kennypu

$date = date("m-d-Y",strtotime($yourdate));