TypechoJoeTheme

EYblog - Powered by Eyblog

统计
登录
用户名
密码

郑先森灬

世上没有偶然,有的只是必然,正面面对困难,才能迈向成功。
网站页面

【技术解读】用php获取本周,上周,本月,上月,本季度日期的代码

PHP date函数参数详解

time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧
不过这样方便计算,
要找出前一天的时间就是 time()-606024;
要找出前一年的时间就是 time()606024365
那么如何把这个数字换成日期格式呢,就要用到date函数了
$t=time();
echo date("Y-m-d H:i:s",$t);
第一个参数的格式分别表示:
a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
D - 星期几,三个英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小时制的小时; 如: "01" 至 "12"
H - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
M - 月份,三个英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365"
其它不在上列的字符则直接列出该字符

下面是实际使用方式:

<?php
  echo date("Ymd",strtotime("now")), "\n";
  echo date("Ymd",strtotime("-1 week Monday")), "\n";
  echo date("Ymd",strtotime("-1 week Sunday")), "\n";
  echo date("Ymd",strtotime("+0 week Monday")), "\n";
  echo date("Ymd",strtotime("+0 week Sunday")), "\n";
  
  echo "*********第几个月:";
  echo date('n');
  echo "*********本周周几:";
  echo date("w");
  echo "*********本月天数:";
  echo date("t");
  echo "*********";
  
  echo '<br>上周起始时间:<br>';
  echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
  echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
  echo '<br>本周起始时间:<br>';
  echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
  echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
 
  //从第几周找出该周的开始日期和结束日期
  $dayNumber = date('W') * 7;
  $weekDayNumber = date("w", mktime(0, 0, 0, 1, $dayNumber, date("Y")));//当前周的第几天
  $startNumber = $dayNumber - $weekDayNumber;
  echo date("Y-m-d", mktime(0, 0, 0, 1, $startNumber + 1, date("Y")));//开始日期
  echo date("Y-m-d", mktime(0, 0, 0, 1, $startNumber + 7, date("Y")));//结束日期 
 
  echo '<br>上月起始时间:<br>';
  echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
  echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
  echo '<br>本月起始时间:<br>';
  echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
  echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";
  
  $season = ceil((date('n'))/3);//当月是第几季度
  echo '<br>本季度起始时间:<br>';
  echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
  echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
  
  $season = ceil((date('n'))/3)-1;//上季度是第几季度
  echo '<br>上季度起始时间:<br>';
  echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
  echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
?>

输出结果

赞(0)
版权属于:

EYblog - Powered by Eyblog

本文链接:

https://akxdz.com/index.php/archives/64/(转载时请注明本文出处及文章链接)

评论 (72)
  1. Pillheest 作者
    Windows 7 · Google Chrome

    buying ed pills online erectile dysfunction medicines men's ed pills

    2022-05-16 回复
  2. Richardheest 作者
    Windows 7 · Google Chrome

    anti fungal pills without prescription cat antibiotics without pet prescription canadian drug pharmacy

    2022-05-15 回复
  3. Richardheest 作者
    Windows 7 · Google Chrome

    buy finasteride generic finasteride for sale purchase finasteride without a prescription

    2022-05-13 回复
  4. Richardheest 作者
    Windows 10 · Google Chrome

    prescription drugs canada buy online best online canadian pharmacy pet meds without vet prescription canada

    2022-05-11 回复
  5. Nathannus 作者
    Windows 7 · Google Chrome

    prednisone 5mg capsules generic prednisone 3000mg prednisone

    2022-05-11 回复
  6. Nathannus 作者
    Windows 10 · Google Chrome

    buy cialis no prescription overnight cialis usa online cialis 30 mg dose

    2022-05-10 回复
  7. Nathannus 作者
    Windows 8.1 · Google Chrome

    ed cure ed meds online without doctor prescription drugs prices

    2022-05-09 回复
  8. Nathannus 作者
    Windows 8.1 · Google Chrome

    buy cialis on line buy cialis without doctor prescription cialis paypal payment canada

    2022-05-05 回复
  9. Iduoit9gxl 作者
    Windows 10 · Google Chrome

    Вам 101 726 р
    Подробнее по ссылке: https://forms.yandex.ru/u/7auj02l94rw254nv9ari/success/?AAAAAakxdz.comBBBBB

    2022-05-03 回复
  10. RobertUSELS 作者
    Windows 10 · Google Chrome

    buy stromectol 6 mg online stromectol drops stromectol drug

    2022-05-03 回复
  11. RobertUSELS 作者
    Windows 8.1 · Google Chrome

    stromectol tablets stromectol buy stromectol side effects

    2022-05-01 回复
  12. RobertUSELS 作者
    Windows 7 · Google Chrome

    can you buy stromectol over the counter ivermectin for dogs tractor supply ivermectin candida

    2022-04-30 回复
  13. RobertUSELS 作者
    Windows 8.1 · Google Chrome

    buy cialis singapore cialis tablets australia generic cialis uk online

    2022-04-29 回复
  14. RobertUSELS 作者
    Windows 10 · Google Chrome

    ivermectin dispersible tablets buy ivermectin cream buy ivermectin online

    2022-04-27 回复
  15. Victortoisa 作者
    Windows 8.1 · Google Chrome

    psychological ed treatment best online pharmacy viagra without a doctor prescription

    2022-04-24 回复
  16. Victortoisa 作者
    Windows 7 · Google Chrome

    best online pharmacy non prescription ed drugs ed treatment review

    2022-04-23 回复
  17. Victortoisa 作者
    Windows 10 · Google Chrome

    canadian online drugs online canadian pharmacy ed medicine

    2022-04-21 回复
  18. JasonDaync 作者
    Windows 8.1 · Google Chrome

    doxycycline online uk 100 doxycycline doxycycline 100

    2022-04-20 回复
  19. JasonDaync 作者
    Windows 7 · Google Chrome

    how much is amoxicillin prescription buying amoxicillin in mexico how to buy amoxycillin

    2022-04-19 回复
  20. JasonDaync 作者
    Windows 10 · Google Chrome

    amoxicillin 500 mg online amoxicillin over the counter in canada amoxicillin capsule 500mg price

    2022-04-17 回复
  21. Josephboime 作者
    Windows 7 · Google Chrome

    doxycycline 100mg acne how to order doxycycline doxycycline 100mg dogs

    2022-04-16 回复
  22. Josephboime 作者
    Windows 8.1 · Google Chrome

    canada buy prednisone online 10 mg prednisone tablets cortisol prednisone

    2022-04-14 回复
  23. Josephboime 作者
    Windows 10 · Google Chrome

    54 prednisone 20 mg prednisone buy 10 mg prednisone

    2022-04-13 回复
  24. Josephboime 作者
    Windows 10 · Google Chrome

    buy amoxicillin buy cheap amoxicillin buy cheap amoxicillin

    2022-04-12 回复
  25. RichardVen 作者
    Windows 8.1 · Google Chrome

    how many 5mg cialis can i take at once 20mg cialis generic cialis efectos secundarios

    2022-04-10 回复
  26. RichardVen 作者
    Windows 10 · Google Chrome

    cialis sublingual cialis for sale over the counter canada cialis for sale

    2022-04-08 回复
  27. Dadhar 作者
    Windows 10 · Google Chrome

    stromectol cvs can you buy stromectol over the counter herbal equivalent to ivermectin

    2022-04-07 回复
  28. JaDiAl 作者
    Windows 10 · Google Chrome

    generic cialis 10mg 30 pills cialis paypal payment canada generic cialis in canada

    2022-04-04 回复
  29. JaDiAl 作者
    Windows 7 · Google Chrome

    comparison of 10 mg cialis price can i take cialis with daxpoteine rx online cialis

    2022-04-03 回复
  30. Jasonbof 作者
    Windows 8.1 · Google Chrome

    does viagra make you bigger or just hard what happens if you take viagra and you don't need it how to tell if a man is taking viagra
    https://cutt.ly/NDOL9An# can i take 200mg of viagra
    best place to buy viagra online forum how to tell if a man is taking viagra how much does viagra cost without insurance

    2022-04-01 回复
  31. Jasonbof 作者
    Windows 7 · Google Chrome

    cialis hk cialis time to work free trial cialis

    2022-03-27 回复
  32. Jasonbof 作者
    Windows 10 · Google Chrome

    what exactly does viagra do? non prescription viagra alternative over the counter viagra substitute walmart

    2022-03-25 回复
  33. Daviddum 作者
    Windows 10 · Google Chrome

    chewable viagra soft tabs what does viagra look like best way to take viagra

    2022-03-24 回复
  34. Daviddum 作者
    Windows 10 · Google Chrome

    doxycycline online without prescription oral doxycycline buy doxycycline 100mg online usa

    2022-03-23 回复
  35. Daviddum 作者
    Windows 10 · Google Chrome

    buy cheap generic viagra what is better viagra or levitra viagra for sale in south africa

    2022-03-22 回复
  36. Daviddum 作者
    Windows 10 · Google Chrome

    doxycycline pharmacy uk doxycycline capsules india purchase doxycycline online uk

    2022-03-20 回复
  37. Marcusthake 作者
    Windows 7 · Google Chrome

    ivermectin scabies buy online ivermectin pigeon ivermectin injectable for horses

    2022-03-19 回复
  38. Marcusthake 作者
    Windows 8.1 · Google Chrome

    ivermectin 1.87 dosage for humans what does ivermectin treat in dogs ivermectin lung cancer

    2022-03-18 回复
  39. Marcusthake 作者
    Windows 7 · Google Chrome

    ivermectin sheep drench dosage how fast does ivermectin work ivermectin dose for humans

    2022-03-17 回复
  40. Jameselirl 作者
    Windows 8.1 · Google Chrome

    cialis overnight delivery cialis vs viagra cialis only

    2022-03-13 回复
  41. Jameselirl 作者
    Windows 8.1 · Google Chrome

    cialis nz cialis cialis 30 day free trial

    2022-03-12 回复
  42. Russellepife 作者
    Windows 10 · Google Chrome

    plaquenil covid hydroxychloroquine 200 mg hcq over the counter

    2022-03-10 回复
  43. Russellepife 作者
    Windows 7 · Google Chrome

    paxlovid patient fact sheet paxlovid prix covid antiviral pills

    2022-03-08 回复
  44. Russellepife 作者
    Windows 7 · Google Chrome

    hydroxychloroquine 400 mg buy online hcq for sale plaquenil and covid

    2022-03-07 回复
  45. Russellepife 作者
    Windows 8 · Google Chrome

    paxlovid canada paxlovid clinical trial paxlovid drug interactions list

    2022-03-06 回复
  46. Stevenprish 作者
    Windows 7 · Google Chrome

    high blood pressure viagra how to make homemade viagra do you need prescription for viagra

    2022-03-03 回复
  47. Stevenprish 作者
    Windows 7 · Google Chrome

    how much does the military spend on viagra generic viagra without prescription difference between cialis and viagra

    2022-03-02 回复
  48. MathewMiz 作者
    Windows 8.1 · Google Chrome

    buy doxycycline online buy doxycycline online uk - buy doxycycline online without prescription
    https://doxycyline1st.com/# doxycycline without prescription

    2022-03-01 回复
  49. MathewMiz 作者
    Windows 8.1 · Google Chrome

    100mg doxycycline where can i get doxycycline - generic doxycycline
    https://doxycyline1st.com/# generic for doxycycline

    2022-02-28 回复
  50. MathewMiz 作者
    Windows 7 · Google Chrome

    how to order doxycycline doxycycline 500mg - doxycycline 200 mg
    https://doxycyline1st.com/# doxycycline mono

    2022-02-26 回复
  51. Jamesdor 作者
    Windows 7 · Google Chrome

    clomid cost clomid tablet - clomid dosage
    https://clomiphene1st.com/# clomid online purchase

    2022-02-25 回复
  52. Stevenvap 作者
    Windows 8.1 · Google Chrome

    https://stromectolis.com/# stromectol coronavirus

    2022-02-22 回复
  53. Stevenvap 作者
    Windows 7 · Google Chrome

    https://stromectolis.com/# ivermectin gel

    2022-02-22 回复
  54. Stevenvap 作者
    Windows 10 · Google Chrome

    https://stromectolis.com/# stromectol where to buy

    2022-02-21 回复
  55. Stevenvap 作者
    Windows 10 · Google Chrome

    https://stromectolis.com/# ivermectin 3mg tablets

    2022-02-21 回复
  56. Stevenvap 作者
    Windows 7 · Google Chrome

    https://stromectolis.com/# stromectol uk

    2022-02-21 回复
  57. Stevenvap 作者
    Windows 7 · Google Chrome

    https://stromectolis.com/# stromectol online canada

    2022-02-21 回复
  58. Stevenvap 作者
    Windows 7 · Google Chrome

    https://stromectolis.com/# ivermectin new zealand

    2022-02-20 回复
  59. Stevenvap 作者
    Windows 10 · Google Chrome

    https://stromectolis.com/# ivermectin uk coronavirus

    2022-02-20 回复
  60. Chrisskelf 作者
    Windows 7 · Google Chrome

    ivermectin pills: ivermectin - ivermectin tablets
    https://stromectolst.com/# ivermectin syrup
    stromectol where to buy stromectol for sale stromectol 12mg

    2022-02-18 回复
  61. Chrisskelf 作者
    Windows 10 · Google Chrome

    stromectol usa: buy stromectol - stromectol for humans
    http://stromectolst.com/# ivermectin nz
    stromectol 3 mg price ivermectin ivermectin lice oral

    2022-02-17 回复
  62. Georgelajow 作者
    Windows 10 · Google Chrome

    cheap paxlovid where can i get paxlovid buy paxlovid
    https://myalliancehealthcare.online/ buy molnupiravir
    buy molnupiravir online molnupiravir where can i get molnupiravir

    2022-02-16 回复
  63. Georgelajow 作者
    Windows 7 · Google Chrome

    cheap paxlovid paxlovid purchase paxlovid
    https://apollobgshospitalsmysore.online/ paxlovid for sale
    cost of molnupiravir buy molnupiravir molnupiravir india

    2022-02-15 回复
  64. Georgelajow 作者
    Windows 7 · Google Chrome

    paxlovid for sale buy paxlovid paxlovid price
    https://myalliancehealthcare.online/ molnupiravir
    buy molnupiravir molnupiravir cost of molnupiravir

    2022-02-15 回复
  65. JamesAmand 作者
    Windows 8 · Google Chrome

    best non prescription ed pills anti fungal pills without prescription canadian drugs online
    https://without-prescription-online.com/ canadian online drugs
    meds online without doctor prescription buy prescription drugs without doctor pet meds without vet prescription

    2022-02-12 回复
  66. JamesAmand 作者
    Windows 10 · Google Chrome

    the canadian drugstore canadian drug legal to buy prescription drugs without prescription
    https://without-prescription-online.online/ pet antibiotics without vet prescription
    prescription without a doctor's prescription prescription drugs without prior prescription canadian drugs

    2022-02-12 回复
  67. JamesAmand 作者
    Windows 10 · Google Chrome

    cvs prescription prices without insurance canadian drugs online ed meds online without doctor prescription
    https://without-prescription-online.online/ canadian online pharmacy
    mexican pharmacy without prescription canadian online pharmacy pet antibiotics without vet prescription

    2022-02-11 回复
  68. GrantTOT 作者
    Windows 8.1 · Google Chrome

    where can you buy zithromax zithromax online paypal zithromax 250 mg australia
    https://azithromycin1st.com/ zithromax 250 mg australia
    buy zithromax 1000 mg online where to get zithromax zithromax cost australia

    2022-02-10 回复
  69. GrantTOT 作者
    Windows 10 · Google Chrome

    buy zithromax online zithromax 500 zithromax prescription in canada
    https://azithromycin1st.com/ zithromax order online uk
    buy azithromycin zithromax zithromax price canada buy zithromax 1000mg online

    2022-02-10 回复
  70. GrantTOT 作者
    Windows 10 · Google Chrome

    zithromax online generic zithromax over the counter can i buy zithromax over the counter
    https://azithromycin1st.com/ zithromax for sale us
    can you buy zithromax over the counter in mexico zithromax antibiotic zithromax capsules

    2022-02-10 回复
  71. GrantTOT 作者
    Windows 8.1 · Google Chrome

    buy zithromax 1000mg online zithromax how to get zithromax over the counter
    https://azithromycin1st.com/ zithromax for sale usa
    zithromax capsules 250mg where to get zithromax over the counter zithromax online usa

    2022-02-09 回复
  72. Timothypoism 作者
    Windows 8.1 · Google Chrome

    ivermectin price canada stromectol for humans for sale - cost of ivermectin
    http://stromectolabc.online/ ivermectin lotion
    ivermectin pill cost stromectol stromectol tablet 3 mg

    2022-02-05 回复
郑先森灬
世上没有偶然,有的只是必然,正面面对困难,才能迈向成功。
24 文章数
25,899 评论量

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月