用程序输出从星期日至星期六,每天变化的只是日期而星期不变
我弄了一个简单的程序,原先的意思是输出星期日至星期六,但是现在我搞的每天日期和星期都在变化,我想要的结果是这样:
2014-9-28(星期日)
2014-9-29(星期一)
2014-9-30(星期二)
2014-10-1(星期三)
2014-10-2(星期四)
2014-10-3(星期五)
2014-10-4(星期六)
到了2014-10-5(星期日)。。。。。一次类推,只有日期在变,而星期不变,这个怎么实现的呢?这个是我原先的程序,
function getWeek($day){ $days = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); $day = explode('-',$day); return $days[date('w',mktime(0,0,0,$day[1],$day[2],$day[0]))];}<?phpfor($i = 0;$i < 7;$i++){$day = date('Y-m-d',strtotime(''.($i+1).' day'));echo $day."(".getWeek($day).")";}?>
回复讨论(解决方案)
这个意思?
function getWeek($day){ $days = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); return $days[date('w', strtotime($day))];}$date = '2014-09-29';if($w = date('w', strtotime($date))) $date = date('Y-m-d', strtotime("-$w day $date"));for($i = 0;$i < 7;$i++){$day = date('Y-m-d',strtotime("$i day $date"));echo $day."(".getWeek($day).")\n";}
这个意思?
function getWeek($day){ $days = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); return $days[date('w', strtotime($day))];}$date = '2014-09-29';if($w = date('w', strtotime($date))) $date = date('Y-m-d', strtotime("-$w day $date"));for($i = 0;$i < 7;$i++){$day = date('Y-m-d',strtotime("$i day $date"));echo $day."(".getWeek($day).")\n";}
就是这种效果,但是版主定义的$date=‘2014-09-29’起什么作用呢?
我理解成楼主想要这周的周一到周日。。。
header("Content-Type: text/html; charset=utf-8");
$timestamp=time();
$is_return_timestamp=false;
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;
}
}
$Monday=strtotime($cache[$id]);
$Tuesday=$Monday+3600*24*1;
$Wednesday=$Monday+3600*24*2;
$Thursday=$Monday+3600*24*3;
$Friday=$Monday+3600*24*2;
$Saturday=$Monday+3600*24*6;
$Sundany=$Monday+3600*24*6;
echo $cache[$id].'周一
' ;
echo date("Y-m-d",$Tuesday).'周二
';
echo date("Y-m-d",$Wednesday).'周三
';
echo date("Y-m-d",$Thursday).'周四
';
echo date("Y-m-d",$Friday).'周五
';
echo date("Y-m-d",$Saturday).'周六
';
echo date("Y-m-d",$Sundany).'周日
';
?>
$Saturday=$Monday+3600*24*5; 这地方改下。。
function getWeek($day){ $days = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); return $days[$day];}for($i=0;$i<7;$i++){ $a=strtotime("+$i day"); $b=getWeek(date('w',$a)); $c=date('y-m-d',$a); echo "20$c$b<br/>";}
2014-09-28星期日2014-09-29星期一2014-09-30星期二2014-10-01星期三2014-10-02星期四2014-10-03星期五2014-10-04星期六

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1. First open the mobile web browser, search for the Weibo web version, and click the avatar button in the upper left corner after entering. 2. Then click Settings in the upper right corner. 3. Click the version switching option in settings. 4. Then select the color version option in the version switch. 5. Click Search to enter the search page. 6. After entering the keywords, click Find People. 7. When the search completion interface appears, click Filter. 8. Finally, enter the specific date in the release time column and click Filter.

1. Let me first talk about the method I used at the beginning, maybe everyone is using it too. First, open [View]——]Remarks Template[. 2. A place where you can actually see the date after opening it. 3. Select it first and delete it. 4. After deleting, click [Close Master View]. 5. Open the print preview again and find that the date is still there. 6. In fact, this date was not deleted here. It should be in the [Handout Master]. Look at the picture below. 7. Delete the date after you find it. 8. Now when you open the preview and take a look, the date is no longer there. Note: In fact, this method is also very easy to remember, because the printed handouts are handouts, so you should look for the [Handout Master].

By default, the top bar of Ubuntu 17.10 only has the current time and no date. What should I do if I want to display the date? Let’s take a look at the detailed tutorial below. 1. Open the terminal in the launcher, or press [Ctrl+Alt+T] 2. Enter in the terminal: sudoaptinstallgnome-tweak-tool 3. After the installation is completed, open the tweak tool 4. Click TopBar 5. Date is the date and seconds is the number of seconds 6. After setting it up, the date and seconds will be displayed on the time in the top bar.

When performing data analysis in Python, it is also necessary to group and summarize by date, for example, to find the periodic pattern of sales volume. Then before using Python for data statistics, you need to add an extra step: get the day of the week from the specified date. For example, February 22, 2022, happens to be the 22nd Tuesday of the first lunar month, so there are particularly many people registering for marriage on this day. This article takes 2022-02-22 as an example to demonstrate 6 ways to get the "day of the week" for a specified date in Python! The weekday() datetime module is a Python built-in library that does not require pip installation. In addition to displaying date and time, it can also perform date and time calculations and formatting.

Excel software has very powerful data processing functions. We often use excel software to process various data. Sometimes when we enter a date in an excel cell, the date in excel changes to a pound sign. How can we display the data normally? Let’s take a look at the solution below. 1. First, we put the mouse on the column width line between columns AB, double-click and adjust the column width, as shown in the figure below. 2. After the column is widened, we find that numbers are displayed in the cells instead of dates. This is definitely incorrect. Then we should check the format of the cells, as shown in the figure below. 3. Click the "Number" option in the "Home" tab, and click "Other Number Format" in the drop-down menu, as shown in the figure below.

How to use the time and date modules in Python Introduction: In programming, dealing with time and dates are very common tasks. Python provides powerful time and date modules, making time and date operations easier and more convenient. This article will introduce the time and date modules in Python and provide specific code examples to help readers better understand and apply them. 1. Introducing the time and date module Python’s built-in time and date module is the datetime module. We need to introduce this module first.

Generating random data is very important in the field of data science. From building neural network predictions, stock market data, etc., date is usually used as one of the parameters. We may need to generate random numbers between two dates for statistical analysis. This article will show how to generate k random dates between two given dates using the random and datetime modules. Datetime is Python’s built-in library for handling time. On the other hand, the random module helps in generating random numbers. So we can combine random and datetime modules to generate a random date between two dates. Syntax random.randint (start, end, k) random here refers to the Python random library. The randint method uses three important

PHP Data Filtering: Processing Date and Time Input Overview: When developing web applications, it is often necessary to process date and time data entered by the user. Since user input may contain various formats and errors, effective data filtering and validation are necessary to ensure data accuracy and security. This article explains how to use PHP to handle date and time input, and provides corresponding code examples. Filtering and validation principles: Before processing date and time inputs, you first need to determine the corresponding filtering and validation principles. Here are some common ones
