如果我已经知道年份和该年的第几周(一年有52周),求这个周的初始日期和结束日期。代码如下: 1 function GetWeekDate( $year , $week ) 2 { 3 $months = array ("1"="Jan.","2"="Feb.","3"="Mar.","4"="Apr.","5"="May.","6"="Jun.","7"="Jul.","8"="Aug."
如果我已经知道年份和该年的第几周(一年有52周),求这个周的初始日期和结束日期。代码如下:
<span> 1</span> <span>function</span> GetWeekDate( <span>$year</span>,<span>$week</span><span>) </span><span> 2</span> <span>{ </span><span> 3</span> <span>$months</span> = <span>array</span>("1"=>"Jan.","2"=>"Feb.","3"=>"Mar.","4"=>"Apr.","5"=>"May.","6"=>"Jun.","7"=>"Jul.","8"=>"Aug.","9"=>"Sep.","10"=>"Oct.","11"=>"Nov.","12"=>"Dec."<span>); </span><span> 4</span> <span>$time</span> = <span>strtotime</span>("1 January <span>$year</span>", <span>time</span><span>()); </span><span> 5</span> <span>$day</span> = <span>date</span>('w', <span>$time</span><span>);//求1月1号是第1周的哪一天,0表示星期一,6表示星期日 </span><span> 6</span> <span>$time</span> += ((7*(<span>$week</span>-1))+1-<span>$day</span>)*24*3600<span>;//时间回归到该年第一周的第一天,因为1月1号并不一定是星期一 </span><span> 7</span> <span>$m1</span> = <span>date</span>('m', <span>$time</span><span>); </span><span> 8</span> <span>$d1</span> = <span>date</span>('d', <span>$time</span><span>); </span><span> 9</span> <span>$time</span> += 6*24*3600<span>;//每周的初始时间与结束时间的时间间隔 </span><span>10</span> <span>$m2</span> = <span>date</span>('m', <span>$time</span><span>); </span><span>11</span> <span>$d2</span> = <span>date</span>('d', <span>$time</span><span>); </span><span>12</span> <span>return</span> <span>$year</span>." the week ".<span>$week</span>. 'th('.<span>$months</span>[(int)<span>$m1</span>].<span>$d1</span>.'-'.<span>$months</span>[(int)<span>$m2</span>].<span>$d2</span>.')'<span>; </span><span>13</span> }
测试结果:
$year=2014;
$week=7;//第七周
echo GetWeekDate($year,$week);//得到的结果是:2014 the week 7th(Feb.10-Feb.16)
查询日历验证2014年第七周的初始时间(周一)是2014.2.10,结束时间(周日)是2014.2.16。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
