duanque19820925 2018-03-16 09:49 采纳率: 0%
浏览 38

指定日期是周末和/或假日PHP

I need to write a program that generates a random date

$start = strtotime('2010-01-01');
$end =  strtotime('2018-01-01');
$random_date = date('n F Y l ', rand($start, $end));

then I need to translate the names of months and days into russian

$lat = array ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'January', 'February', 'March', 'April', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$rus = array ('Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Января', 'Февраля', 'Марта', 'Апреля', 'Июня', 'Июля', 'Августа', 'Сентября', 'Октября', 'Ноября', 'Декабря');
return str_replace($lat,$rus, $random_date) ; 
$holidays = array('8 января','7 января','14 января', '23 февраля','8 марта','1 апреля','12 апреля','1 мая','9 мая','12 июня','22 июня','1 сентября','27 сентября','4 ноября','12 декабря','31 декабря','1 января');//dates of rus holidays

Then I need to display the date in this format:
2 Февраля 2014 Пятница (2 February 2014 Friday).

Here's what I am having trouble with:

The end result must look like this: 2 February 2014 Friday holiday and/or weekend. So, I need to specify whether the displayed date is a weekend or/ and a holiday. Could someone help?

  • 写回答

2条回答 默认 最新

  • dongyi1215 2018-03-16 11:35
    关注

    You put the date in $date, then we set $weekend to false until we check it, then we check the date and if it is a weekend set $weekend to true. then if the date is a weekend I print it is a weekend and if it is not i print it is not a weekend, but you can do anything you like with it...

    date = '2018-03-16';
    $weekend = false;
    $day = date("D", strtotime($date));
    if($day == 'Sat' || $day == 'Sun'){
        $weekend = true;
    }
    if($weekend){
        echo $date . ' It is a weekend';
    } else{
        echo $date . ' It is not a weekend';
    }
    

    and as function(didnt test this one yet):

    function isitweekend($date){
    $date = '2018-03-16';
    $weekend = false;
    $day = date("D", strtotime($date));
    if($day == 'Sat' || $day == 'Sun'){
        $weekend = true;
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序