如何在PHP(多平台)中获取给定星期数的第一天? [英] How to get the first day of a given week number in PHP (multi-platform)?

查看:73
本文介绍了如何在PHP(多平台)中获取给定星期数的第一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中最简单的方法是什么?

What is the simplest way to do it in PHP ?

我想要一年中给定星期几的星期一的日期(例如:2009年的第3周)

I want the date of the Monday of a given week number of a year (example : week number 3 of 2009)

谢谢!

如果您仅使用Linux机器,请使用cletus的解决方案,但是我正在寻找可以在Windows和Linux上运行的工具.

EDIT : If you use Linux only machines, use cletus' solution, however I am looking for something that can work on Windows AND Linux.

推荐答案

另一个解决方案:

<?php
        $week = 3;
        $year = 2009;

        $timestamp = mktime( 0, 0, 0, 1, 1,  $year ) + ( $week * 7 * 24 * 60 * 60 );
        $timestamp_for_monday = $timestamp - 86400 * ( date( 'N', $timestamp ) - 1 );
        $date_for_monday = date( 'Y-m-d', $timestamp_for_monday );
?>

这篇关于如何在PHP(多平台)中获取给定星期数的第一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆