php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法

2013-7-15 liyangweb.com 李杨 PHP

php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime。下面首先还是直奔主题以示例说明如何使用 mktime 获取今日、昨日、上周、本月的起始时间戳和结束时间戳,然后在介绍一下 mktime 函数作用和用法。
 
//php获取今日开始时间戳和结束时间戳
 
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
 
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
 
//php获取昨日起始时间戳和结束时间戳
 
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
 
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
 
//php获取上周起始时间戳和结束时间戳
 
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
 
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
 
//php获取本月起始时间戳和结束时间戳
 
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
 
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
PHP mktime() 函数用于返回一个日期的 Unix 时间戳。
 
语法
 
mktime(hour,minute,second,month,day,year,is_dst)
 
参数 描述
hour 可选。规定小时。
minute 可选。规定分钟。
second 可选。规定秒。
month 可选。规定用数字表示的月。
day 可选。规定天。
year 可选。规定年。在某些系统上,合法值介于 1901 - 2038 之间。不过在 PHP 5 中已经不存在这个限制了。
is_dst
可选。如果时间在日光节约时间(DST)期间,则设置为1,否则设置为0,若未知,则设置为-1。
 
自 5.1.0 起,is_dst 参数被废弃。因此应该使用新的时区处理特性。
 
用法
 
参数总是表示 GMT 日期,因此 is_dst 对结果没有影响。
 
参数可以从右到左依次空着,空着的参数会被设为相应的当前 GMT 值。
 
注意在 PHP 5.1 之前,如果该函数的参数非法,则会返回 false。
 
另外需要注意的是该函数对于日期运算和验证非常有用。它可以自动校正越界的输入,如:
 
 
echo(date("M-d-Y",mktime(0,0,0,12,36,2001)));
 
将输出结果如:Jan-05-2002

评论:

miembrojr
2019-02-10 08:13
<a href="http://www.wuxiangtaichi.com/nike-kyrie-1-rosa-nero-scarpeh">nike kyrie 1 rosa nero</a> <a href="http://www.culdesacmag.com/hommes-nike-air-max-2017-noir-rose-chaussuresp">hommes nike air max 2017 noir rose</a> <a href="http://www.livinggreedy.com/green-north-face-puffer-jacket-northfaceh">green north face puffer jacket</a> <a href="http://www.clickstroy.com/dam%C3%A4nner-nike-air-max-tn-rot-wei%C3%9F-schuheq">dam盲nner nike air max tn rot wei脽</a> <a href="http://www.zotorrent.com/nike-zoom-winflo-3-oranger-chaussuresl">nike zoom winflo 3 oranger</a> <a href="http://www.viptarimas.com/air-jordan-true-flight-hombresta-verde-cielo-azul-zapatosq">air jordan true flight hombresta verde cielo azul</a>
miembrojr http://www.miembrojr.com/
munchstrom
2019-01-29 05:33
<a href="http://www.drtruth.net/nike-free-mercurial-superfly-by-htm-herren-schuh-kurpese">nike free mercurial superfly by htm herren schuh</a> <a href="http://www.drybulkintelligence.net/nike-tiempo-legend-v-hvit-svart-treasure-bl%C3%A5-kurpesa">nike tiempo legend v hvit svart treasure bl氓</a> <a href="http://www.dsicomposer.net/air-yeezy-ii-2-sp-max-90-svart-l%C3%A6r-chaussuresb">air yeezy ii 2 sp max 90 svart l忙r</a> <a href="http://www.duckbeachmovie.net/femminile-nike-free-3.0-viola-grigio-obuve">femminile nike free 3.0 viola grigio</a> <a href="http://www.dynamicbook.net/adidas-springblade-rot-and-schwarz-keys-chaussuresa">adidas springblade rot and schwarz keys</a> <a href="http://www.earlylearninggroup.net/air-jordan-1-brun-lyser%C3%B8d-butya">air jordan 1 brun lyser酶d</a>
munchstrom http://www.munchstrom.net/
gospeedbird
2019-01-21 09:02
<a href="http://www.aloulavideos.com/nfl-matt-bosher-mens-elite-black-jersey-5-atlanta-falcons-nike-alternate-vapor-untouchable-nflx">nfl matt bosher mens elite black jersey 5 atlanta falcons nike alternate vapor untouchable</a> <a href="http://www.brutalistmap.com/nike-air-max-95-neutral-grau-chlorine-blau-kurpesc">nike air max 95 neutral grau chlorine blau</a> <a href="http://www.glassurchin.com/womens-nike-new-orleans-saints-22-mark-ingram-elite-green-salute-to-service-nfl-jersey-nflx">womens nike new orleans saints 22 mark ingram elite green salute to service nfl jersey</a> <a href="http://www.hevikauppa.com/air-jordan-retro-5-mujeres-plata-rosado-obuvd">air jordan retro 5 mujeres plata rosado</a> <a href="http://www.indegrow.com/adidas-ultra-boost-herre-gr%C3%A5-mac-scarpec">adidas ultra boost herre gr氓 mac</a> <a href="http://www.motiongfxart.com/nike-sock-dart-sp-blanc-bleu-kurpesb">nike sock dart sp blanc bleu</a>
gospeedbird http://www.gospeedbird.com/
nrastogi
2019-01-17 20:06
<a href="http://www.kainjipark.com/nike-free-5.0-v4-hvid-metalleic-s%C3%B8lv-kurpesb">nike free 5.0 v4 hvid metalleic s酶lv</a> <a href="http://www.lapthelakes.com/y-3-kyujo-low-shoes-man-y-3-adidas-zapatost">y 3 kyujo low shoes man y 3 adidas</a> <a href="http://www.delmaroffice.com/custom-painted-converse-uk-shoesz">custom painted converse uk</a> <a href="http://www.medieneinsatz.com/nike-zoom-clear-out-2-vert-bleu-schuheb">nike zoom clear out 2 vert bleu</a> <a href="http://www.linexcanton.com/bayern-munchen-32-kimmich-home-long-sleeves-soccer-club-jersey-nflu">bayern munchen 32 kimmich home long sleeves soccer club jersey</a> <a href="http://www.saskostomy.com/nike-air-huarache-run-ultra-skou">nike air huarache run ultra</a>
nrastogi http://www.nrastogi.com/
kosarkomur
2019-01-05 07:29
<a href="http://www.rcnspecials.com/nike-lebron-11-basketballe-schuhe-schuhef">nike lebron 11 basketballe schuhe</a> <a href="http://www.aprancheta.com/nike-air-max-90-em-schuhe-naranja-schwarz-gelb-obuvg">nike air max 90 em schuhe naranja schwarz gelb</a> <a href="http://www.getleanlearn.com/air-max-zero-qs-nero-queen-chaussuresa">air max zero qs nero queen</a> <a href="http://www.hbshbuick.com/air-max-97-plata-hombres-butya">air max 97 plata hombres</a> <a href="http://www.hvactampafl.com/jordan-1-royal-near-me-obuvc">jordan 1 royal near me</a> <a href="http://www.zinmanlaw.com/nike-air-max-90-kpu-orange-gr%C3%BCn-scarpea">nike air max 90 kpu orange gr眉n</a>
kosarkomur http://www.kosarkomur.com/
nvusforex
2019-01-04 15:25
<a href="http://www.evolutionecig.com/converse-femme-all-star-blanche-shoesz">converse femme all star blanche</a> <a href="http://www.georginabauer.com/nike-hyperdunk-2015-low-wei%C3%9F-lila-schuheb">nike hyperdunk 2015 low wei脽 lila</a> <a href="http://www.bootsoffprice.com/nike-womens-brandon-mebane-limited-olive-jersey-los-angeles-chargers-nfl-92-2017-salute-to-service-nflu">nike womens brandon mebane limited olive jersey los angeles chargers nfl 92 2017 salute to service</a> <a href="http://www.theprintjobs.com/nike-blazer-low-vintage-womens-skou">nike blazer low vintage womens</a> <a href="http://www.dbajournal.com/nike-pegasus-33-purple-runningf">nike pegasus 33 purple</a> <a href="http://www.procomedian.com/nike-air-max-1-premium-black-and-white-zapatosu">nike air max 1 premium black and white</a>
nvusforex http://www.nvusforex.com/
katasuto
2019-01-03 19:29
<a href="http://www.abobaday.com/nike-kobe-9-high-jaune-argent-schuheg">nike kobe 9 high jaune argent</a> <a href="http://www.bucketgrills.com/nike-air-max-1-essential-gris-rouge-trainers-kurpesc">nike air max 1 essential gris rouge trainers</a> <a href="http://www.christinabox.com/air-jordan-ultra-fly-orange-blanc-obuvg">air jordan ultra fly orange blanc</a> <a href="http://www.jennymarston.com/asics-asics-gel-kayano-17-azul-p%C3%BArpura-scarpee">asics asics gel kayano 17 azul p煤rpura</a> <a href="http://www.shufiparis.com/lebron-12-verde-and-gris-butya">lebron 12 verde and gris</a> <a href="http://www.thermosolid.com/lunarglide-8-femminile-uk-scarpe-chaussuresf">lunarglide 8 femminile uk scarpe</a>
katasuto http://www.katasuto.com/
mylinkstv
2019-01-01 08:47
<a href="http://www.ntygadget.com/adidas-nmd-runner-alle-schwarz-ops-scarpeb">adidas nmd runner alle schwarz ops</a> <a href="http://www.purchasetulsa.com/nike-air-max-95-green-spain-shoeso">nike air max 95 green spain</a> <a href="http://www.pennywave.com/nike-air-max-mujeres-maroon-kurpesb">nike air max mujeres maroon</a> <a href="http://www.scoptix.com/michael-jordan-shoes-for-women-zapatost">michael jordan shoes for women</a> <a href="http://www.domodrzwi.com/custom-painted-converse-uk-shoesz">custom painted converse uk</a> <a href="http://www.magneticduo.com/nike-free-flyknit-5.0-l%C3%B8ping-sko-x10-schuhec">nike free flyknit 5.0 l酶ping sko x10</a>
mylinkstv http://www.mylinkstv.com/
firmayoga
2018-12-31 11:28
<a href="http://www.emmamoney.com/nike-zoom-vomero-11-azul-obuvd">nike zoom vomero 11 azul</a> <a href="http://www.guntruthers.com/kvinners-nike-roshe-run-slip-gul-gr%C3%A5-scarpea">kvinners nike roshe run slip gul gr氓</a> <a href="http://www.jayandarmando.com/hombres-nike-air-huarache-rojo-verde-schuhec">hombres nike air huarache rojo verde</a> <a href="http://www.mikevi.com/adidas-bruins-77-ray-bourque-camo-authentic-2017-veterans-day-stitched-nhl-jersey-nflr">adidas bruins 77 ray bourque camo authentic 2017 veterans day stitched nhl jersey</a> <a href="http://www.mynaturalogy.com/nike-womens-bryan-anger-game-orange-alternate-jersey-tampa-bay-buccaneers-nfl-9-nflx">nike womens bryan anger game orange alternate jersey tampa bay buccaneers nfl 9</a> <a href="http://www.wvusigmakappa.com/air-jordan-size-us14-us15-gr%C3%A5-gul-schuheg">air jordan size us14 us15 gr氓 gul</a>
firmayoga http://www.firmayoga.com/
jugarcalle
2018-12-31 04:54
<a href="http://www.entrustengage.com/womens-reggie-white-limited-black-nike-jersey-nfl-philadelphia-eagles-92-alternate-vapor-untouchable-nflx">womens reggie white limited black nike jersey nfl philadelphia eagles 92 alternate vapor untouchable</a> <a href="http://www.frissedenkers.com/nike-air-zoom-total-90-wei%C3%9F-rot-gr%C3%BCn-butyd">nike air zoom total 90 wei脽 rot gr眉n</a> <a href="http://www.jauntycouture.com/zx-flux-torsion-sort-and-guld-kurpesd">zx flux torsion sort and guld</a> <a href="http://www.myshinnies.com/herre-ralph-lauren-sweater-r%C3%B8d-bl%C3%A5-polow">herre ralph lauren sweater r酶d bl氓</a> <a href="http://www.thecreditgods.com/air-jordan-4-blanco-plata-butyf">air jordan 4 blanco plata</a> <a href="http://www.zinoviaenache.com/ralph-lauren-tracksuit-gr%C3%B8nn-beige-poloz">ralph lauren tracksuit gr酶nn beige</a>
[url=http://www.jugarcalle.com/]jugarcalle[/url]
nishajagmohan
2018-12-30 03:11
<a href="http://www.tickbits.com/adidas-crazylight-boost-womens-pink-gold-skoe">adidas crazylight boost womens pink gold</a> <a href="http://www.jmgtours.com/roshe-run-turquoise-gray-pink-skoc">roshe run turquoise gray pink</a> <a href="http://www.gregertopsoil.com/nike-air-max-2010-herren-blau-shoesc">nike air max 2010 herren blau</a> <a href="http://www.nedshare.com/billig-adidas-zx-750-dam%C3%A4nner-schwarz-trainersb">billig adidas zx 750 dam盲nner schwarz</a> <a href="http://www.itmontwitter.com/lebron-12-shoes-grey-and-orange-skob">lebron 12 shoes grey and orange</a> <a href="http://www.itsanomadlife.com/nike-lebron-soldier-9-purple-orange-sneakerb">nike lebron soldier 9 purple orange</a>
nishajagmohan http://www.nishajagmohan.com/

发表评论:

Powered by emlog 冀ICP备13011830号-1