计算一个月的剩余天数

杰西·斯托克

因此,假设我有一个能够选择月份中特定日期的用户。假设他愿意选择2014年10月16日,那么我想将每月剩余的日期显示为日历。

<?php
error_reporting(0);

$data  = $_POST['input'];
$days = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');

$m = date('m'); $y = date('y');
$d = cal_days_in_month(CAL_GREGORIAN,$m,$y);

for ($i=1;$i<;$i++){ 
    echo $i + 1; 
}

到目前为止,代码还很混乱。我没有办法解决这个问题,这就是为什么我问。

h2ooooooo

您可以使用strtotimedate

对于格式,date可以使用以下命令:

't'给定月份中的天数(28到31
'j',每月中没有前导零(1到31)的天数

<?php

$timestamp = strtotime('2014-10-03');

$daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);

var_dump($daysRemaining); // int(28)

演示


编辑:显然您想列出一个月中的剩余天数:

<?php

$timestamp = strtotime('2014-10-03');
$yearMonth = date('Y-m-', $timestamp);

$daysInMonth = (int)date('t', $timestamp);

for ($i = (int)date('j', $timestamp); $i <= $daysInMonth; $i++) {
    $dateString = date('l \t\h\e jS \o\f F', strtotime($yearMonth . $i));

    var_dump($dateString);
}

/*
    string(25) "Friday the 3rd of October"
    string(27) "Saturday the 4th of October"
    string(25) "Sunday the 5th of October"
    string(25) "Monday the 6th of October"
    string(26) "Tuesday the 7th of October"
    string(28) "Wednesday the 8th of October"
    string(27) "Thursday the 9th of October"
    string(26) "Friday the 10th of October"
    string(28) "Saturday the 11th of October"
    string(26) "Sunday the 12th of October"
    string(26) "Monday the 13th of October"
    string(27) "Tuesday the 14th of October"
    string(29) "Wednesday the 15th of October"
    string(28) "Thursday the 16th of October"
    string(26) "Friday the 17th of October"
    string(28) "Saturday the 18th of October"
    string(26) "Sunday the 19th of October"
    string(26) "Monday the 20th of October"
    string(27) "Tuesday the 21st of October"
    string(29) "Wednesday the 22nd of October"
    string(28) "Thursday the 23rd of October"
    string(26) "Friday the 24th of October"
    string(28) "Saturday the 25th of October"
    string(26) "Sunday the 26th of October"
    string(26) "Monday the 27th of October"
    string(27) "Tuesday the 28th of October"
    string(29) "Wednesday the 29th of October"
    string(28) "Thursday the 30th of October"
    string(28) "Friday the 31st of October"
*/

演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

计算一个月的天数

来自分类Dev

计算一个月的天数

来自分类Dev

如何获得一个月剩余的可用天数进行预订?

来自分类Dev

日期,找出一个月的天数

来自分类Dev

乘以一个月的天数

来自分类Dev

mysql计算一个月中的不同天数

来自分类Dev

在 SAS 中计算一个月中的天数

来自分类Dev

如何计算另一个日期的剩余天数

来自分类Dev

如何计算另一个日期的剩余天数

来自分类Dev

计算超过一个月的延迟

来自分类Dev

给定的天数超过一周,一个月或一年

来自分类Dev

如何在Dart / Flutter中获得一个月的天数?

来自分类Dev

java Date 和 LocalDateTime 中一个月的天数

来自分类Dev

如何使用moment php打印一个月的天数?

来自分类Dev

计算日期范围内一个月内的天数

来自分类Dev

如何从一个日期中查找一个月的剩余日期?

来自分类Dev

SQL:一个月中的总天数

来自分类Dev

如何增加一个月中的天数?

来自分类Dev

一个月中周末的天数

来自分类Dev

计算一天,一周,一个月的用户注册

来自分类Dev

如何计算一个月的工作时间?

来自分类Dev

在java.time中,如何计算一个月的结果?

来自分类Dev

计算Google表格中日期列表中一个月的实例数

来自分类Dev

JavaScript-奇怪地使用Date.getDate()来获取一个月的天数。这是如何运作的?

来自分类Dev

前一个月的查询/表达

来自分类Dev

as3-加一个月

来自分类Dev

从即日起一个月

来自分类Dev

Rails:如何遍历一个月?

来自分类Dev

从Datetime.Today减去一个月