代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PHP
】
获取每个月的第一个星期的日期
作者:
Dezai.CN
/ 发布于
2011/6/11
/
461
<div><span style="font-style: italic; color: rgb(128,128,128)">/** * This function calculates the first [WEEKDAY] of a month. * The day to find is passed as an integer to the function. * * To use: Pass the month, year and day (as an integer 0-6) to the function. * * @param int $month * @param int $year * @param int $day [0 = sunday, 1 = monday, 2 = tuesday, 3 = wednesday, 4 = thursday, 5 = friday, 6 = saturday] * @return date */</span> <span style="color: rgb(0,0,0); font-weight: bold">function</span> getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$month</span>,<span style="color: rgb(0,0,255)">$year</span>,<span style="color: rgb(0,0,255)">$day</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">{</span> <span style="color: rgb(0,0,255)">$num</span> = <a href="http://www.php.net/date" target="_blank"><span style="color: rgb(0,0,102)">date</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">"w"</span>,<a href="http://www.php.net/mktime" target="_blank"><span style="color: rgb(0,0,102)">mktime</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(0,0,255)">$month</span>,<span style="color: rgb(204,102,204)">1</span>,<span style="color: rgb(0,0,255)">$year</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$num</span>==<span style="color: rgb(0,0,255)">$day</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <span style="color: rgb(177,177,0)">return</span> <a href="http://www.php.net/date" target="_blank"><span style="color: rgb(0,0,102)">date</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">"Y-m-d H:i:s"</span>,<a href="http://www.php.net/mktime" target="_blank"><span style="color: rgb(0,0,102)">mktime</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(0,0,255)">$month</span>,<span style="color: rgb(204,102,204)">1</span>,<span style="color: rgb(0,0,255)">$year</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(102,204,102)">}</span> <span style="color: rgb(177,177,0)">elseif</span><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$num</span>><span style="color: rgb(0,0,255)">$day</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <span style="color: rgb(177,177,0)">return</span> <a href="http://www.php.net/date" target="_blank"><span style="color: rgb(0,0,102)">date</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">"Y-m-d H:i:s"</span>,<a href="http://www.php.net/mktime" target="_blank"><span style="color: rgb(0,0,102)">mktime</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(0,0,255)">$month</span>,<span style="color: rgb(204,102,204)">1</span>,<span style="color: rgb(0,0,255)">$year</span><span style="color: rgb(102,204,102)">)</span>+<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">86400</span>*<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">7</span>+<span style="color: rgb(0,0,255)">$day</span><span style="color: rgb(102,204,102)">)</span>-<span style="color: rgb(0,0,255)">$num</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(102,204,102)">}</span> <span style="color: rgb(177,177,0)">else</span> <span style="color: rgb(102,204,102)">{</span> <span style="color: rgb(177,177,0)">return</span> <a href="http://www.php.net/date" target="_blank"><span style="color: rgb(0,0,102)">date</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">"Y-m-d H:i:s"</span>,<a href="http://www.php.net/mktime" target="_blank"><span style="color: rgb(0,0,102)">mktime</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(204,102,204)">0</span>,<span style="color: rgb(0,0,255)">$month</span>,<span style="color: rgb(204,102,204)">1</span>,<span style="color: rgb(0,0,255)">$year</span><span style="color: rgb(102,204,102)">)</span>+<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(204,102,204)">86400</span>*<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$day</span>-<span style="color: rgb(0,0,255)">$num</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">)</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(102,204,102)">}</span> <span style="color: rgb(102,204,102)">}</span> <span style="font-style: italic; color: rgb(128,128,128)">// Example of use:</span> <span style="color: rgb(0,0,255)">$sunday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">0</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Sunday</span> <span style="color: rgb(0,0,255)">$monday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">1</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Monday</span> <span style="color: rgb(0,0,255)">$tuesday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">2</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Tuesday</span> <span style="color: rgb(0,0,255)">$wednesday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">3</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Wednesday</span> <span style="color: rgb(0,0,255)">$thursday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">4</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Thursday</span> <span style="color: rgb(0,0,255)">$friday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">5</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Friday</span> <span style="color: rgb(0,0,255)">$saturday</span> = getFirstDay<span style="color: rgb(102,204,102)">(</span><span style="color: rgb(255,0,0)">'1'</span>,<span style="color: rgb(255,0,0)">'2009'</span>,<span style="color: rgb(204,102,204)">6</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">// Saturday</span> <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Sunday: "</span> . <span style="color: rgb(0,0,255)">$sunday</span> . <span style="color: rgb(255,0,0)">""</span>; <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Monday: "</span> . <span style="color: rgb(0,0,255)">$monday</span> . <span style="color: rgb(255,0,0)">""</span>; <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Tuesday: "</span> . <span style="color: rgb(0,0,255)">$tuesday</span> . <span style="color: rgb(255,0,0)">""</span>; <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Wednesday: "</span> . <span style="color: rgb(0,0,255)">$wednesday</span> . <span style="color: rgb(255,0,0)">""</span>; <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Thursday: "</span> . <span style="color: rgb(0,0,255)">$thursday</span> . <span style="color: rgb(255,0,0)">""</span>; <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Friday: "</span> . <span style="color: rgb(0,0,255)">$friday</span> . <span style="color: rgb(255,0,0)">""</span>; <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"First Saturday: "</span> . <span style="color: rgb(0,0,255)">$saturday</span> . <span style="color: rgb(255,0,0)">""</span>; </div>
试试其它关键字
同语言下
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
可能有用的
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3