2015-11-19 82 views
3

我想申请比赛项目。优胜者将在本月的最后一天公布。即:当前月份是11月。我想显示如下信息:Final declaration will be announced at 30th November 10:00:00 pm如何获得当月的最后一天?

我想从php函数获得30th November 10:00:00 pm。任何想法?

+0

使用't'在日期功能,见http://stackoverflow.com/a/1686742/3112492 – chrisjacob

+0

[见这个问题(HTTP ://stackoverflow.com/questions/16351396/how-to-get-last-day-of-the-month-using-php) –

回答

2

这会产生相同的结果:

<?php 
    $last = date('t F 10:00:00') . "pm"; 
    echo $last; 
?> 
1

date返回格式化的日期字符串,并接受格式说明符作为第一个参数,并将可选的第二个参数作为时间戳记。所以date本身并不会让你想要你想要的,除非你首先计算当前月份的最后一天作为Unix时间戳并将其提供给date

你可以用strtotime来做到这一点,它接受字符串形式的relative date/times,并以整数形式将它们转换回Unix时间戳。

echo date('jS F g:i:s a', strtotime('last day of this month')); 
// should give you something like 30th November 1:02:02 pm 
相关问题