//本周的第一天和最后一天

 代码如下 复制代码
$date=new DateTime();
$date->modify('this week');
$first_day_of_week=$date->format('Y-m-d');
$date->modify('this week +6 days');
$end_day_of_week=$date->format('Y-m-d');

经过测试modity不知道是用做什么了,于时找了另两个例子

 代码如下 复制代码

//这个星期的星期一

// @$timestamp ,某个星期的某一个时间戳,默认为当前时间

// @is_return_timestamp ,是否返回时间戳,否则返回时间格式

function this_monday($timestamp=0,$is_return_timestamp=true){

static $cache ;

$id = $timestamp.$is_return_timestamp;

if(!isset($cache[$id])){

if(!$timestamp) $timestamp = time();

$monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6*86400*/518400));

if($is_return_timestamp){

$cache[$id] = strtotime($monday_date);

}else{

$cache[$id] = $monday_date;

}

}

return $cache[$id];

}

//这个星期的星期天

 代码如下 复制代码

// @$timestamp ,某个星期的某一个时间戳,默认为当前时间

// @is_return_timestamp ,是否返回时间戳,否则返回时间格式

function this_sunday($timestamp=0,$is_return_timestamp=true){

static $cache ;

$id = $timestamp.$is_return_timestamp;

if(!isset($cache[$id])){

if(!$timestamp) $timestamp = time();

$sunday = this_monday($timestamp) + /*6*86400*/518400;

if($is_return_timestamp){

$cache[$id] = $sunday;

}else{

$cache[$id] = date('Y-m-d',$sunday);

}

}

return $cache[$id];

}

 

PHP获取本周第一天和最后一天的更多相关文章

  1. C#获取本周第一天和最后一天

    DateTime nowTime = DateTime.Now; #region 获取本周第一天 //星期一为第一天 int weeknow = Convert.ToInt32(nowTime.Day ...

  2. JS 获取(期号、当前日期、本周第一天、最后一天及当前月第一、最后天函数)    

    JS 获取(期号.当前日期.本周第一天.最后一天及当前月第一.最后天函数 /** 2 * 获取当前月期号 3 * 返回格式: YYYY-mm 4 * / 5 function getCurrentMo ...

  3. java获取本月第一天和最后一天

    public class CalendarTest { public static void main(String[] args) { // 获取当前年份.月份.日期 Calendar cale = ...

  4. Java获取某年第一天和最后一天

    package com.dada.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.uti ...

  5. java 获取当月第一天和最后一天 获取前一个月第一天和最后一天

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");                    //获取前月的第一 ...

  6. JS获取当月第一天和最后一天

    /** * 获取当前月的第一天 */function getCurrentMonthFirst(){ var date=new Date(); date.setDate(1); return date ...

  7. WinForm------DateTime获取月第一天和最后一天取法

    转载: http://blog.csdn.net/livening/article/details/6049341/ 代码: /// <summary> /// 取得某月的第一天 /// ...

  8. oracle获取本月第一天和最后一天及Oracle trunc()函数的用法

    select to_char(trunc(add_months(last_day(sysdate), -1) + 1), 'yyyy-mm-dd') "本月第一天", to_cha ...

  9. C#获取当月第一天和最后一天

    当月第一天0时0分0秒: DateTime.Now.AddDays(1 - DateTime.Now.Day).Date 当月最后一天23时59分59秒: DateTime.Now.AddDays(1 ...

随机推荐

  1. Spring和Hibernate集成的HibernateTemplate的一些常用方法总结

    1:get/load存取单条数据 public Teacher getTeacherById(Long id) { return (Teacher)this.hibernateTemplate.get ...

  2. UVa784 Maze Exploration

    // 题意:输入一个迷宫,从*开始遍历,把可达点标记为字符# 注意迷宫边界不规则,要用strlen判断. #include<cstdio> #include<cstring> ...

  3. iOS UIButton EdgeInsets

    说一下系统的button,image 和 title的位置关系 默认image 和 title的位置关系: 随便画了草图,有点丑,不过不妨碍理解: 第一种:在button上只设置文字,这个时候,but ...

  4. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  5. Codeforces Gym 100338B Geometry Problem 计算几何

    Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  6. [Angular-Scaled Web] 9. Control your promises with $q

    Learn how to manually control how asynchronous requests are handled with the use of promises. Becaus ...

  7. Html&CSS 今日心得

    今天和秋秋一起review了一下我自己写的登录页面.她给我提了几个point,对我很有启发. css样式的代码和html代码分离. 我自己做的时候是在google console里面调好了样式以后就直 ...

  8. 判断文件是否为UTF8编码

    utf8的规则比较简单: 对于UTF-8编码中的任意字节B,如果B的第一位为0,则B为ASCII码,并且B独立的表示一个字符; 如果B的第一位为1,第二位为0,则B为一个非ASCII字符(该字符由多个 ...

  9. percona-toolkit工具包的使用教程

    http://blog.chinaunix.net/uid-20639775-id-3236916.html     本文收集了percona-toolkit工具包中比较常用的工具集,写成教程,方便自 ...

  10. Android:Activity之间跳转和参数传递

    一个activity就好比一个网页,此文章讲解怎样创建一个activity并且实现跳转! 一.学习创建Activity 1.新建一个java类,右击src目录,选择new-->class,新的a ...