V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cevincheung
V2EX  ›  PHP

酔酔的…… 获取本月的第一天从 0 点开始到本月最后一天 23 点 59 分 59 秒的起始时间戳。

  •  
  •   cevincheung · 2015-09-15 18:44:19 +08:00 · 3677 次点击
    这是一个创建于 3155 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <?php
    $ld = in_array (date ('m'),[1,3,5,7,8,10,12]) ? 31 : ( date ('m') == 2 ? ( date ('L') ? 29 : 28 ) : 30 );
    $start = mktime (0,0,0,date ('m'),1,date ('Y'));
    $end = mktime (23,59,59,date ('m'),$ld,date ('Y'));
    

    看了那个批斗滥用三元表达式的帖子后毅然决然的改成酱紫 :doge:

    <?php
    $start = mktime (0,0,0,date ('m'),1,date ('Y'));
    $end = mktime (23,59,59,date ('m'),date ('t'),date ('Y'));
    

    晓得 datetime 和 strtotime 就不用批斗我这个了……就是闲的没事作的 :doge:

    12 条回复    2015-09-16 11:52:34 +08:00
    shiye515
        1
    shiye515  
       2015-09-15 19:59:01 +08:00 via Android
    这个月最后一秒就是下个月第一秒减一秒
    moro
        2
    moro  
       2015-09-15 20:21:31 +08:00
    $start = strtotime ('first day of 0 month 00:00:00')
    $end = strtotime ('last day of 0 month 23:59:59')
    Lucius
        3
    Lucius  
       2015-09-15 20:28:42 +08:00
    @moro

    666 我还以为是我回的帖,吓窝一大跳
    hgwang1215
        4
    hgwang1215  
       2015-09-15 20:43:55 +08:00
    长得太像了~
    flowfire
        5
    flowfire  
       2015-09-15 20:59:17 +08:00
    ......难道不是应该算第一秒的时间戳然后循环+1 一直到最后一秒么。。。
    jerray
        6
    jerray  
       2015-09-15 23:28:59 +08:00
    cevincheung
        7
    cevincheung  
    OP
       2015-09-16 00:09:29 +08:00
    @flowfire 66666666
    skydiver
        8
    skydiver  
       2015-09-16 03:21:12 +08:00 via iPad
    最后一秒直接用下一天第一秒减一就行了,没必要这么麻烦
    morefreeze
        9
    morefreeze  
       2015-09-16 10:11:10 +08:00
    我还是十分建议你用 0 秒<=x<下一月 0 秒
    realpg
        11
    realpg  
       2015-09-16 11:41:20 +08:00
    楼上更正 卧槽搞错了 date ("Y-m-1");
    wuling
        12
    wuling  
       2015-09-16 11:52:34 +08:00
    有个类叫 datetime
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2212 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:08 · PVG 00:08 · LAX 09:08 · JFK 12:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.