如何在 PHP 中创建今天 MM/DD/YYYY 格式的变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1135573/
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
How do I create a variable in PHP of today's date of MM/DD/YYYY format?
提问by Timothy T.
How do I create a variable in PHP of today's date of MM/DD/YYYY format?
如何在 PHP 中创建今天 MM/DD/YYYY 格式的变量?
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.
当有人访问网站时,我需要将该日期作为隐藏表单字段输入。所以我需要获取今天的日期并将其转换为该格式。谢谢。
回答by farzad
回答by Sadegh
$Date = date('m/d/Y');
回答by Pascal MARTIN
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
使用函数date怎么样?只需要找到正确的格式;例如,'m' 代表月份,'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.
如果您想改天,请使用第二个可选参数。
回答by Kalpesh Desai
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
回答by Imran Khan
<?php
$currentdate = date('m/d/Y');
echo "The Current Date is: $currentdate";
?>

