php - 在 php 或 javascript 中列出带有日期名称的每个日期
问题描述
有没有办法在 php 或 javascript 中列出每个日期和日期名称?例子
- 1月1日星期三
- 1月2日星期四
- 1月3日星期五
等等等等,如果有人可以传播一些关于是否以及如何做到这一点的信息,我将不胜感激。谢谢你。
解决方案
您可以使用DatePeriod
.
$start = new DateTime('1/1'); // first day of the current year
$interval = new DateInterval('P1D'); // iterate 1 day at a time
$end = new DateTime('1/1 next year'); // stop when we get to first day of next year
// All of these periods are equivalent.
$period = new DatePeriod($start, $interval, $end);
// By iterating over the DatePeriod object, all of the
// recurring dates within that period are printed.
foreach ($period as $date) {
echo $date->format('Y-m-d')."\n";
}
这将为您提供当年的每一天。
推荐阅读
- r - R中所有列的相同循环以创建新数据框
- python - 需要在网页中集成 Python 解释器,该网页将代码发布到执行它的服务器
- postgresql - 如何根据其他参数仅在某些记录上过滤表?
- rust - 为什么修改可变借用变量并保持其未使用不会引发错误
- apache-spark - apache spark phoenix 连接器不支持流式读取
- ibm-mobilefirst - WKWebViewEngine 仅在与 cordova-plugin-mfp 结合使用时显示空白屏幕
- python - Tkinter 比例和动画不会运行
- javascript - 如何在 v-for 中使用 if 语句?
- php - 我们渴望条件分支
- c# - 如何在 C# 中设置授权标头