怎么用php来获取时间 周次 节次来做签到功能

怎么用php来获取时间 周次 节次来做签到功能,第1张

签到功能主要是需要获取上次签到时间,然后进行比对,如果比较之后在零点之后,且大于24小时,就认为连续签到失败。

关键点:每次需要记录签到时间,这样以后无论是根据记录,还是相应算法都可以统计相关的签到记录。

签到功能核心就是时间的比较,只要比对好时间,然后封装签到方法,就可以轻松记录签到情况。

PHP的date函数是十分强大的。提供了非常多的格式给我们用。这里主要使用date相关函数就能达成目的,下面直接上代码。

<php

    $timestr = time();

    $now_day = date('w',$timestr);

    //获取一周的第一天,注意第一天应该是星期

    $sunday_str = $timestr - $now_day606024;

    $sunday = date('Y-m-d', $sunday_str);

    //获取一周的最后一天,注意最后一天是星期六

    $strday_str = $timestr + (6-$now_day)606024;

    $strday = date('Y-m-d', $strday_str);

    echo "星期天: $sunday\n";

    echo "星期六: $strday\n";

    exit;

>

输出结果:

如果你要星期一到星期日的自行加减一天

一般是用js来显示:

今天是<script language="javascript">RunGLNL();</script>

        2014年12月28日 星期日 农历冬月初七

<script>function RunGLNL(){var e=new Date,t=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"),i=egetFullYear()+"年"+[egetMonth()+1]+"月"+egetDate()+"日";intHours=egetHours(),intMinutes=egetMinutes(),intSeconds=egetSeconds(),0==intHours(hours="12:",xfile=""):12>intHours(hours=intHours+":",xfile=""):12==intHours(hours="12:",xfile=""):(intHours-=12,hours=intHours+":",xfile=""),minutes=10>intMinutes"0"+intMinutes+":":intMinutes+":",seconds=10>intSeconds"0"+intSeconds+" ":intSeconds+" ",i=i+" "+t[egetDay()];var i=i+" "+CnDateofDateStr(e);i+=SolarTerm(e),documentwrite(i)}function DaysNumberofDate(e){return parseInt((Dateparse(e)-Dateparse(egetFullYear()+"/1/1"))/864e5)+1}function CnDateofDate(e){var t,i,a,n,r,o,s,l,d=new Array(22,42,218,0,131,73,182,5,14,100,187,0,25,178,91,0,135,106,87,4,18,117,43,0,29,182,149,0,138,173,85,2,21,85,170,0,130,85,108,7,13,201,118,0,23,100,183,0,134,228,174,5,17,234,86,0,27,109,42,0,136,90,170,4,20,173,85,0,129,170,213,9,11,82,234,0,22,169,109,0,132,169,93,6,15,212,174,0,26,234,77,0,135,186,85,4),c=new Array,h=new Array,u=new Array,p=egetFullYear();if(egetMonth()+1,egetDate(),100>p&&(p+=1900),1997>p||p>2020)return 0;for(u[0]=d[4(p-1997)],u[1]=d[4(p-1997)+1],u[2]=d[4(p-1997)+2],u[3]=d[4(p-1997)+3],c[0]=0!=(128&u[0])12:11,t=127&u[0],n=u[1],n<<=8,n|=u[2],i=u[3],a=15;a>=0;a--)h[15-a]=29,0!=(1<<a&n)&&h[15-a]++,c[15-a]==ic[15-a+1]=-i:(c[15-a+1]=c[15-a]<0-c[15-a]+1:c[15-a]+1,c[15-a+1]>12&&(c[15-a+1]=1));if(r=DaysNumberofDate(e)-1,r<=h[0]-t)s=p>1901&&CnDateofDate(new Date(p-1+"/12/31"))<0-c[0]:c[0],l=t+r;else{for(o=h[0]-t,a=1;r>o&&o+h[a]<r;)o+=h[a],a++;s=c[a],l=r-o}return s>0100s+l:100s-l}function CnYearofDate(e){var t=egetFullYear(),i=egetMonth()+1,a=parseInt(Mathabs(CnDateofDate(e))/100);return 100>t&&(t+=1900),a>i&&t--,t-=1864,CnEra(t)+"年"}function CnMonthofDate(e){var t,i=new Array("零","正","二","三","四","五","六","七","八","九","十","冬","腊");return t=parseInt(CnDateofDate(e)/100),0>t"闰"+i[-t]+"月":i[t]+"月"}function CnDayofDate(e){var t,i=new Array("零","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");return t=Mathabs(CnDateofDate(e))%100,i[t]}function DaysNumberofMonth(e){var t=egetFullYear();100>tt+=1900:t;var i=t;return t+="/"+(egetMonth()+1),i+="/"+(egetMonth()+2),t+="/1",i+="/1",parseInt((Dateparse(i)-Dateparse(t))/864e5)}function CnEra(e){var t=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸"),i=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");return t[e%10]+i[e%12]}function CnDateofDateStr(e){return"零月"==CnMonthofDate(e)" 请调整您的计算机日期!":"农历"+CnMonthofDate(e)+CnDayofDate(e)}function SolarTerm(e){var t=new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"),i=new Array(1272060,1275495,1281180,1289445,1299225,1310355,1321560,1333035,1342770,1350855,1356420,1359045,1358580,1355055,1348695,1340040,1329630,1318455,1306935,1297380,1286865,1277730,1274550,1271556),a=31556926,n=new Date(1901);for(nsetTime(94712046e4);egetFullYear()<ngetFullYear();)nsetTime(ngetTime()-1e3a);for(;egetFullYear()>ngetFullYear();)nsetTime(ngetTime()+1e3a);for(var r=0;egetMonth()>ngetMonth();r++)nsetTime(ngetTime()+1e3i[r]);egetDate()>ngetDate()&&(nsetTime(ngetTime()+1e3i[r]),r++),egetDate()>ngetDate()&&(nsetTime(ngetTime()+1e3i[r]),23==rr=0:r++);var o="";return egetDate()==ngetDate()&&(o+="     <i>"+t[r]+"</i>"),o}</script>

本周周一的日期:

$ts = time();

$this_monday = this_monday($ts);

echo date('Y-m-d H:i:s', $this_monday);

//这个星期的星期一  

// @$timestamp ,某个星期的某一个时间戳,默认为当前时间  

// @is_return_timestamp ,是否返回时间戳,否则返回时间格式  

function this_monday($timestamp=0,$is_return_timestamp=true){  

    static $cache ;  

    $id = $timestamp$is_return_timestamp;  

    if(!isset($cache[$id])){  

        if(!$timestamp) $timestamp = time();  

        $monday_date = date('Y-m-d', $timestamp-86400date('w',$timestamp)+(date('w',$timestamp)>086400:-/686400/518400));  

        if($is_return_timestamp){  

            $cache[$id] = strtotime($monday_date);  

        }else{  

            $cache[$id] = $monday_date;  

        }  

    }  

    return $cache[$id];  

   

}

上周一的函数则为

$ts = time();

$last_monday = last_monday($ts);

echo date('Y-m-d H:i:s', $last_monday);

//上周一  

// @$timestamp ,某个星期的某一个时间戳,默认为当前时间  

// @is_return_timestamp ,是否返回时间戳,否则返回时间格式  

function last_monday($timestamp=0,$is_return_timestamp=true){  

    static $cache ;  

    $id = $timestamp$is_return_timestamp;  

    if(!isset($cache[$id])){  

        if(!$timestamp) $timestamp = time();  

        $thismonday = this_monday($timestamp) - /786400/604800;  

        if($is_return_timestamp){  

            $cache[$id] = $thismonday;  

        }else{  

            $cache[$id] = date('Y-m-d',$thismonday);  

        }  

    }  

    return $cache[$id];  

}

<php

//这个月的 周日-周六的日期

$year = date("Y");

$month = date("m");

$days = date("t");

for ($i=0; $i < $days; $i++) { 

$day = $year'-'$month'-'$i;

$w = date('w',strtotime($day));

  if ($w == 6 || $w ==0) {

  echo $day' 是周末<br />';

  }

><php

//这个周的 周日-周六的日期

$year = date("Y");

$month = date("m");

$days = date("t");

$hao = date('j');

for ($i=$hao; $i < ($hao+7); $i++) { 

$day = $year'-'$month'-'$i;

$w = date('w',strtotime($day));

  if ($w == 6 || $w ==0) {

  echo $day' 是周末<br />';

  }

}

>

望采纳 Thx

<php

$friday = strtotime("Friday");//本周五开始时间

$lastFri = strtotime("last Friday");//上周五开始时间  或者$friday-864007

$nextFri = strtotime("next Friday");//下周五开始时间  或者$friday+864007 注意一下:下周五这个有时会出问题,比如现在还不到周五,这样得到的下周五的时间会和本周五一样。

//如果需要某天截止时间可以在这一天的开始时间加上86400  也就是1天

echo "本周五开始时间是:"date("Y-m-d H:i:s",$friday)"<br />";

echo "上周五开始时间是:"date("Y-m-d H:i:s",$lastFri)"<br />";

echo "下周五开始时间是:"date("Y-m-d H:i:s",$nextFri)"<br />";

希望我的回答对您有所帮助~~

<php

$alive='';

$listr=''; $daycss='';

$ws=array("日","一","二","三","四","五","六");

for($i=-3;$i<4;$i++){

$curdateline=strtotime('+'$i' days');

$curdate=date('md',$curdateline);

$day=date('m月d日',$curdateline);

$week="星期"$ws[date('w',$curdateline)];

echo('<li data-id="'$curdate'" class=""> <a href="/#"><p>'$week'</p>'$day'</a><i class="i-cut"></i></li>');

}

>

以上就是关于怎么用php来获取时间 周次 节次来做签到功能全部的内容,包括:怎么用php来获取时间 周次 节次来做签到功能、php怎么获取本周的时间格式开始和结束、php显示日期,周几,农历初几,什么节日函数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9337766.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存