为给定的一组数据时间获取月的第一个星期一 [英] Get first monday of month for a given set of datetimes
本文介绍了为给定的一组数据时间获取月的第一个星期一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些数据时间列表。我想要获得每个数据时间的第一个星期一。
I have a certain list of datetimes. I want to get the first monday of each datetimes.
例如:假设给定的数据时间是
eg: Suppose the given datetimes are
2013-07-05 2013-08-05, 2013-09-13 etc.
我想得到所有这些数据的第一个星期一,使得输出结果
I want to get the first monday of all these datetimes such that the output results in
2013-07-01, 2013-08-05, 2013-09-02 respectively
我实际上坚持使用 stftime
。
strftime("%d/%m/%Y", strtotime("first Monday of July 2012"));
推荐答案
使用php Datetime类:
Using php Datetime class:
$Dates = array('2013-07-02', '2013-08-05', '2013-09-13');
foreach ($Dates as $Date)
{
$test = new DateTime($Date);
echo $test->modify('first monday')->format('Y-m-d');
}
这篇关于为给定的一组数据时间获取月的第一个星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文