How do I create a variable in PHP of today's date of MM/DD/YYYY format?
如何在今天的MM / DD / YYYY格式日期以PHP创建变量?
I need to input that date as a hidden form field when someone comes onto the site. So I would need to grab today's date and convert it into that format. Thanks.
当有人进入网站时,我需要将该日期输入为隐藏的表单字段。所以我需要抓住今天的日期并将其转换为该格式。谢谢。
5 个解决方案
#1
31
use the builtin date() function.
使用builtin date()函数。
$myDate = date('m/d/Y');
the string parameter 'm/d/Y' is the returned date pattern. m is for 2 digit months, d for 2 digit day value and Y for 4 digit year value.
字符串参数'm / d / Y'是返回的日期模式。 m表示2个数字月份,d表示2位数日值,Y表示4位数年份值。
#2
10
$Date = date('m/d/Y');
#3
6
What about using the function date ? Just have to find the right format ; 'm' for month, 'd' for day, 'Y' for year using four digits, for instance
使用功能日期怎么样?只需找到正确的格式; '是'月份,'d'代表白天,'Y'代表年份,例如四位数
In your case, something like this, I guess :
在你的情况下,我猜这样的事情:
date("m/d/Y")
And if you want another day than now, use the second optional parameter.
如果你想要比现在更多的一天,请使用第二个可选参数。
#4
1
<?php
$currentdate = date('m/d/Y');
echo "The Current Date is: $currentdate";
?>
#5
1
May be this one help you :)
可能这一个帮你:)
<?php echo $todaydate = date('m/d/Y'); ?> // 04/27/2016
<?php echo $todaydate = date('m/d/y'); ?> // 04/27/16
<?php echo $todaydate = date('Y'); ?> // 2016
<?php echo $todaydate = date('Y-m-d'); ?> // 2016-04-27
#1
31
use the builtin date() function.
使用builtin date()函数。
$myDate = date('m/d/Y');
the string parameter 'm/d/Y' is the returned date pattern. m is for 2 digit months, d for 2 digit day value and Y for 4 digit year value.
字符串参数'm / d / Y'是返回的日期模式。 m表示2个数字月份,d表示2位数日值,Y表示4位数年份值。
#2
10
$Date = date('m/d/Y');
#3
6
What about using the function date ? Just have to find the right format ; 'm' for month, 'd' for day, 'Y' for year using four digits, for instance
使用功能日期怎么样?只需找到正确的格式; '是'月份,'d'代表白天,'Y'代表年份,例如四位数
In your case, something like this, I guess :
在你的情况下,我猜这样的事情:
date("m/d/Y")
And if you want another day than now, use the second optional parameter.
如果你想要比现在更多的一天,请使用第二个可选参数。
#4
1
<?php
$currentdate = date('m/d/Y');
echo "The Current Date is: $currentdate";
?>
#5
1
May be this one help you :)
可能这一个帮你:)
<?php echo $todaydate = date('m/d/Y'); ?> // 04/27/2016
<?php echo $todaydate = date('m/d/y'); ?> // 04/27/16
<?php echo $todaydate = date('Y'); ?> // 2016
<?php echo $todaydate = date('Y-m-d'); ?> // 2016-04-27