如何从数据库日期格式打印月份和年份



我的数据库中有日期单元格:createDate这是Y-m-d格式。即:2018-10-31

我如何以这种格式在屏幕上打印它:2018年10月

我试过这个:

echo date ("Y-M", $mainIndex['createDate'])

使用此

echo date ("F Y", strtotime($mainIndex['createDate']));

你非常接近:(第二个参数应该是一个整数(时间(

echo date ("F Y", strtotime($mainIndex['createDate']));

您可以使用日期格式的php函数,类似于

echo date_format($mainIndex['createDate'],"F Y");

欲了解更多信息,请访问php date_format和php日期参数参数

您需要转换时间日期unix时间戳

echo date('F Y', strtotime($mainIndex['createDate']));

最新更新