使用PHP日期和时间函数打印特定句子

使用PHP日期和时间函数打印特定句子,php,datetime,Php,Datetime,我需要PHP日期/时间函数的帮助 使用de date/time功能,我需要打印以下内容: 今天是“当前日期”,是“年”中的“月数”。今天是“一年中的天数”。我们还有“年底前的天数” 就是不能让它工作。。有什么想法吗? 谢谢 好吧,也许有更好的方法,但这是一种获得您所要求的所有不同元素的方法: $d = new DateTime(); $currentDay = $d->format('l'); // Will give you the current day in full (i.e. M

我需要PHP日期/时间函数的帮助

使用de date/time功能,我需要打印以下内容:

今天是“当前日期”,是“年”中的“月数”。今天是“一年中的天数”。我们还有“年底前的天数”

就是不能让它工作。。有什么想法吗?

谢谢

好吧,也许有更好的方法,但这是一种获得您所要求的所有不同元素的方法:

$d = new DateTime();
$currentDay = $d->format('l'); // Will give you the current day in full (i.e. Monday)
$dayOfMonth = $d->format('j'); // Will give you the current day of the Month
$year       = $d->format('Y'); // Will give you the current Year.
$dayOfYear  = ($d->format('z') + 1); // Starts at 0, so we add one to get the actual days past.
至于剩下的日子,我认为可能有更好的方法,但这里有一个快速的解决方案:

$daysInYear = 365;
if ($d->format('L') === 1) { // Returns 1 if leap year.
    $daysInYear = 366;
}
$daysLeft = $daysInYear - $dayOfYear;

这将为您提供打印所需语句所需的所有变量

请阅读。到目前为止你尝试了什么?到目前为止你尝试了什么?对不起,这里还是比较新的,我们会尽快阅读。
到目前为止,我们已经做到了:日期默认时区设置(“欧洲/巴黎”);setlocale(LC_ALL,“欧洲/阿姆斯特丹”);回声“Vandaag是het”。strftime(“%A,%#d/%m/%Y.De tijd为%H:%m:%S”)<代码>如果(日期('L')==1?$last=366-(日期('z')+1):$last=365-(日期('z')+1));回音“今天是“.date('D').”,是“.date('M').”中的“.date('D').”年“.date('Y').”。今天是“.date('z')+1.”年中的一天。我们还有“$last.”天