周数打印日期

发布于 2024-08-04 20:35:46 字数 91 浏览 4 评论 0原文

大家好。

如果我有第 42 周,并且我需要知道本周有哪些日期,Sombardy maby 能否告诉我获取此信息的简单方法?

坦克很多:)

Hallo all.

if i have week number 42 and i need to know what dates there are in this week, can sombardy maby tell me a easy way to get this info?

tanks a lot :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绿萝 2024-08-11 20:35:46
<?php
$date = new DateTime('2009W52');
echo $date->format(DateTime::RFC850);

哪些输出

Monday, 21-Dec-09 00:00:00 EET

您可以修改

$date->modify("last monday");
$date->modify("next monday");

,例如第 1-9 周的“周”必须用零填充

<?php
$date = new DateTime('2009W52');
echo $date->format(DateTime::RFC850);

Which outputs

Monday, 21-Dec-09 00:00:00 EET

and you can modify it like

$date->modify("last monday");
$date->modify("next monday");

Week has to be zero padded for weeks 1-9

空气里的味道 2024-08-11 20:35:46

有一个讨论如何获取本周的第一个日期 (星期一)使用一年中的星期和年份。那应该对你有帮助。

There is a thread discussing how to get the first date of the week (Monday) using the week of the year and the year. That should help you.

愛放△進行李 2024-08-11 20:35:46

我知道您已经接受了答案,但我觉得这段代码也很有用。

$year = date("Y");
$week = date("W"); // Can be replaced with '42' for your example.
$start = strtotime($year.'W'.$week.'1');

这将返回一个 unix 时间戳,有些人发现它更容易操作。

您还可以将其用于 PHP 5.1 及更高版本。

$start = date(datetime::ISO8601, strtotime("2009W421"));

使用上面的方法就可以轻松格式化了。

希望这对某人有用。

-马修

I know you have already accepted an answer, but I feel this bit of code is also useful.

$year = date("Y");
$week = date("W"); // Can be replaced with '42' for your example.
$start = strtotime($year.'W'.$week.'1');

This will return a unix timestamp which some people find easier to manipulate.

You can also use this for PHP 5.1 and higher.

$start = date(datetime::ISO8601, strtotime("2009W421"));

Using the above method you can easily format it.

Hope this provides useful to someone.

-Mathew

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文