|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
理解网站这一概念之后不难看出,任何网站都是由网页组成的,也就是说想完成网站,必须先学会做网页,因此必须要掌握了HTML,才能为今后制作网站打下基础。掌握 <?
//日期特别操作掌握类
//宇凡 8月15日
?>
<?
//获得"YYYY-mm-dd"格局确当前工夫
function NowDate()
{
$result = date("Y")."-".date("m")."-".date("d");
return $result;
}
//获得"YYYY-mm-dd HH:ii:ss"格局确当前工夫
function NowDateTime()
{
$result = date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s");
return $result;
}
//从"YYYY-mm-dd"格局的工夫中提取年
function GetYear($Date)
{
$pos = strpos($Date,"-");
$result = "";
for ($i=0;$i<$pos;$i++)
{
$result = $result.$Date[$i];
}
$month = GetMonth($Date);
$day = GetDay($Date);
if (!checkdate($month,$day,$result))
{
$result = false;
}
return $result;
}
//从"YYYY-mm-dd"格局的工夫中提取月
function GetMonth($Date)
{
$pos1 = strpos($Date,"-");
$pos2 = strrpos($Date,"-");
$result = "";
for ($i=$pos1+1;$i<$pos2;$i++)
{
$result = $result.$Date[$i];
}
$year = GetYear($Date);
$day = GetDay($Date);
if (!checkdate($result,$day,$year))
{
$result = false;
}
return $result;
}
//从"YYYY-mm-dd"格局的工夫中提取日
function GetDay($Date)
{
$pos = strrpos($Date,"-");
$result = "";
for ($i=$pos+1;$i<10;$i++)
{
$result = $result.$Date[$i];
}
$year = GetYear($Date);
$month = GetDay($Date);
if (!checkdate($month,$result,$year))
{
$result = false;
}
return $result;
return $result;
}
//反省闰年,前往布尔值
function CheckLeap($year)
{
$result = (($year % 4 == 0) && (($year % 100 <> 0) || ($year % 400 == 0)));
return $result;
}
//在以后日期上加天数 前往"YYYY-mm-dd"格局的工夫
function AddDay($offset)
{
$year=date("Y");
$month=date("m");
$day=date("d");
for ($i=0;$i<$offset;$i++)
{
switch ($month) {
case 1:
{
if ($day==31) {
$day = 1;
$month = 2;
}
else {
$day=$day + 1;
}
}
break;
case 2:
{
if (CheckLeap($year)) {
if ($day == 29) {
$day = 1;
$month = 3;
}
else {
$day=$day + 1;
}
}
else {
if ($day == 28) {
$day = 1;
$month = 3;
}
else {
$day=$day + 1;
}
}
}
break;
case 3:
{
if ($day==31) {
$day = 1;
$month = 4;
}
else {
$day=$day + 1;
}
}
break;
case 4:
{
if ($day==30) {
$day = 1;
$month = 5;
}
else {
$day=$day + 1;
}
}
break;
case 5:
{
if ($day==31) {
$day = 1;
$month = 6;
}
else {
$day=$day + 1;
}
}
break;
case 6:
{
if ($day==30) {
$day = 1;
$month = 7;
}
else {
$day=$day + 1;
}
}
break;
case 7:
{
if ($day==31) {
$day = 1;
$month = 8;
}
else {
$day=$day + 1;
}
}
break;
case 8:
{
if ($day==31) {
$day = 1;
$month = 9;
}
else {
$day=$day + 1;
}
}
break;
case 9:
{
if ($day==30) {
$day = 1;
$month = 10;
}
else {
$day=$day + 1;
}
}
break;
case 10:
{
if ($day==31) {
$day = 1;
$month = 11;
}
else {
$day=$day + 1;
}
}
break;
case 11:
{
if ($day==30) {
$day = 1;
$month = 12;
}
else {
$day=$day + 1;
}
}
break;
case 12:
{
if ($day==31) {
$day = 1;
$month = 1;
$year = $year + 1;
}
else {
$day=$day + 1;
}
}
}
}
$result=$year."-".$month."-".$day;
return $result;
}
//在以后日期上减天数 前往"YYYY-mm-dd"格局的工夫
function AbateDay($offset)
{
$year=date("Y");
$month=date("m");
$day=date("d");
for ($i=0;$i<$offset;$i++)
{
switch ($month) {
case 1:
{
if ($day==1) {
$day = 31;
$month = 12;
$year = $year - 1;
}
else {
$day=$day - 1;
}
}
break;
case 2:
{
if ($day == 1) {
$day = 31;
$month = 1;
}
else {
$day=$day - 1;
}
}
break;
case 3:
{
if ($day == 1) {
if (CheckLeap($year)) {
$day = 29;
}
else {
$day = 28;
}
$month = 2;
}
else {
$day=$day - 1;
}
}
break;
case 4:
{
if ($day == 1) {
$day = 31;
$month = 3;
}
else {
$day=$day - 1;
}
}
break;
case 5:
{
if ($day == 1) {
$day = 30;
$month = 4;
}
else {
$day=$day - 1;
}
}
break;
case 6:
{
if ($day == 1) {
$day = 31;
$month = 5;
}
else {
$day=$day - 1;
}
}
break;
case 7:
{
if ($day == 1) {
$day = 30;
$month = 6;
}
else {
$day=$day - 1;
}
}
break;
case 8:
{
if ($day == 1) {
$day = 31;
$month = 7;
}
else {
$day=$day - 1;
}
}
break;
case 9:
{
if ($day == 1) {
$day = 31;
$month = 8;
}
else {
$day=$day - 1;
}
}
break;
case 10:
{
if ($day == 1) {
$day = 30;
$month = 9;
}
else {
$day=$day - 1;
}
}
break;
case 11:
{
if ($day == 1) {
$day = 31;
$month = 10;
}
else {
$day=$day - 1;
}
}
break;
case 12:
{
if ($day == 1) {
$day = 30;
$month = 11;
}
else {
$day=$day - 1;
}
}
}
}
$result=$year."-".$month."-".$day;
return $result;
}
//获得以后周第一天 前往"YYYY-mm-dd"格局的工夫
function FirstDayOfThisWeek()
{
$offset=date("w");
if ($offset==0)
{
$offset=7;
}
$offset--;
$result = AbateDay($offset);
return $result;
}
//获得以后周最初一天 前往"YYYY-mm-dd"格局的工夫
function LastDayOfThisWeek()
{
$offset=date("w");
if ($offset==0)
{
$offset=7;
}
$offset = 7 - $offset;
$result = AddDay($offset);
return $result;
}
//获得指定月的天数
function DaysAmountOfThisMonth($month,$year)
{
switch ($month) {
case 1:
$result = 31;
break;
case 2:
{
if (CheckLeap($year)) {
$result = 29;
} else {
$result = 28;
}
break;
}
case 3:
$result = 31;
break;
case 4:
$result = 30;
break;
case 5:
$result = 31;
break;
case 6:
$result = 30;
break;
case 7:
$result = 31;
break;
case 8:
$result = 31;
break;
case 9:
$result = 30;
break;
case 10:
$result = 31;
break;
case 11:
$result = 30;
break;
case 12:
$result = 31;
break;
}
return $result;
}
?>
终于理解了数据库的概念,而且让你兴奋不已的是你终于可以通过PHP来连接数据库了,这期间你是怎么学会的,我们不去考证了,但是事实证明,你已经可以了。 |
|