php 如何在codeigniter中获取当前日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15830364/
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 10:01:52  来源:igfitidea点击:

How to get current date in codeigniter

phpjavascriptcodeignitercodeigniter-2

提问by Edwin Alex

How to get current date in codeigniter in YY-mm-dd format. I wants to get current date in YY-mm-dd frmat and put this value into input text box

如何以 YY-mm-dd 格式在 codeigniter 中获取当前日期。我想在 YY-mm-dd frmat 中获取当前日期并将此值放入输入文本框中

回答by Edwin Alex

You can use the PHP date function.

您可以使用PHP 日期函数

date('Y-m-d');

Up to my knowledge, there is no separate date function in codeigniter.

据我所知,codeigniter 中没有单独的日期函数。

EDIT :

编辑 :

But if you want date in this format 13-04-05 [ yy-mm-dd ], Try this

但是如果你想要这种格式的日期13-04-05 [ yy-mm-dd ],试试这个

date('y-m-d');

For more date formats, check this link PHP Date Formats

有关更多日期格式,请查看此链接PHP 日期格式

回答by archisss

Try to use this is a generic format of DateTime

尝试使用这是 DateTime 的通用格式

echo date('Y-m-d H:i:s');

回答by Limon

What about:

关于什么:

$date = new \Datetime('now');
var_dump($date);

回答by Deepu

use php datefunction

使用phpdate函数

echo date("Y-m-d");

will give you the result

会给你结果

回答by Akash soni

Use php date() function, like this echo Date('Y/m/d'); it give you the desired result!

使用 php date() 函数,像这样 echo Date('Y/m/d'); 它会给你想要的结果!

回答by Infolet.org

if you want the full date:

如果你想要完整的日期:

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

depends your date structure.

取决于你的日期结构。

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

if you want year only, then echo date('Y');is enough

如果你只想要一年,那就 echo date('Y');足够了