如何使用php获取假期的日期 [英] how to get date for holidays using php

查看:755
本文介绍了如何使用php获取假期的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:


  1. 一月第三个星期一 马丁·路德·金日
  2. 复活节 的最后一个星期日
  3. strong>

我想要获得这些日期,以便我可以在日历上标记,来。






MODIFIED ANSWER !!

  $ curYir = date(Y); //当前年

$ MLK = date('Ym-d',strtotime $ curYir third montay)); // marthin luthor king day
$ PD = date('Y-m-d',strtotime(february $ curYir third monday)) // presidents day
$ Est = date('Y-m-d',easter_date($ curYir))); //复活节
$ MDay = date('Y-m-d',strtotime(may $ curYir first monday)); //纪念日
//(may $ curYir last monday)将给你1967年的最后一个星期
//更好地通过循环来确定它
$ eMDay = explode ( - ,$ MDay);
$ year = $ eMDay [0];
$ month = $ eMDay [1];
$ day = $ eMDay [2];

while($ day <= 31){
$ day = $ day + 7;
}
if($ day> 31)
$ day = $ day - 7;

$ MDay = $ year .'-'。$ month .'-'。$ day;
$ LD = date('Y-m-d',strtotime(september $ curYir first monday)); // labor day
$ CD = date('Y-m-d',strtotime(october $ curYir third monday)); // columbus day
$ TH = date('Y-m-d',strtotime(november $ curYir first thourday)); //感谢给
//(november $ curYir last thursday)将给你1967年11月的最后一天
//更好地通过循环来确定它
$ eTH = explode ( - ,$ TH);
$ year = $ eTH [0];
$ month = $ eTH [1];
$ day = $ eTH [2];

while($ day <= 30){
$ day = $ day + 7;
}
if($ day> 30)
//注意本月的日期11月只有30
$ day = $ day - 7;

$ TH = $ year .'-'。$ month .'-'。$ day;


解决方案

strtotime



$ currentYear = date(Y);

MLK Day - echo date('Ym-d',strtotime (Ym-d,strtotime(第三个星期一/ OD二月$ currentYear)的第三个星期一$ currentYear));
总统日 - ));

复活节 - 回音日期('Ym-d',strtotime(march的最后星期日$ currentYear));

纪念日 - 回音日期('Ym-d',strtotime(marchay of march $ currentYear)); / p>

For example the:

  1. 3rd Monday of January for Martin Luther King Day
  2. 3rd Monday of February for Presidents' Day (Washington's Birthday)
  3. Last Sunday of March for Easter
  4. Last Monday of May for Memorial Day

I am trying to get these dates, so that I can mark it on my calendar without manually putting everything for the years to come.


MODIFIED ANSWER!!

$curYir = date("Y");//current year

$MLK = date('Y-m-d', strtotime("january $curYir third monday")); //marthin luthor king day
$PD = date('Y-m-d', strtotime("february $curYir third monday")); //presidents day
$Est =  date('Y-m-d', easter_date($curYir))); // easter 
$MDay = date('Y-m-d', strtotime("may $curYir first monday")); // memorial day
//("may $curYir last monday") will give you the last monday of may 1967
//much better to determine it by a loop
      $eMDay = explode("-",$MDay);
      $year = $eMDay[0];
      $month = $eMDay[1];
      $day = $eMDay[2];

      while($day <= 31){
          $day = $day + 7;
      }
      if($day > 31)
      $day = $day - 7;

      $MDay = $year.'-'.$month.'-'.$day;
$LD = date('Y-m-d', strtotime("september $curYir first monday"));  //labor day
$CD = date('Y-m-d', strtotime("october $curYir third monday")); //columbus day
$TH = date('Y-m-d', strtotime("november $curYir first thursday")); // thanks giving 
//("november $curYir last thursday") will give you the last thursday of november 1967
//much better to determine it by a loop
      $eTH = explode("-",$TH);
      $year = $eTH[0];
      $month = $eTH[1];
      $day = $eTH[2];

      while($day <= 30){
          $day = $day + 7;
      }
      if($day > 30)
      //watch out for the days in the month November only have 30
      $day = $day - 7;

      $TH = $year.'-'.$month.'-'.$day;

解决方案

You can leverage this function of php. strtotime

$currentYear = date("Y");
MLK Day - echo date('Y-m-d', strtotime("third monday of january $currentYear")); Presidents Day - echo date('Y-m-d', strtotime("third monday/OD February $currentYear"));
Easter - echo date('Y-m-d', strtotime("last sunday of march $currentYear"));
Memorial Day - echo date('Y-m-d', strtotime("last monday of march $currentYear"));

这篇关于如何使用php获取假期的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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