获取当前时间的时间戳

Mol*_*far 7 php oop datetime

我有一个当天的日期时间.我需要获得两个unix时间戳的开始和本周的结束.我如何使用dateperiod或dateinterval类?

jac*_*bot 13

$now = time();
$beginning_of_week = strtotime('last Monday', $now); // Gives you the time at the BEGINNING of the week
$end_of_week = strtotime('next Sunday', $now) + 86400; // Gives you the time at the END of the last day of the week
Run Code Online (Sandbox Code Playgroud)

  • 然后检查今天是否是星期一,以及是否将'last Monday'替换为'today'.要查看它是否是当前星期一,请执行`if(date('w',$ now())== 1)` (5认同)
  • 但今天是星期一怎么办呢?我得到了14天的一周. (4认同)

san*_*ure 5

if (date('w', time()) == 1)
    $beginning_of_week = strtotime('Today',time()); 
else 
    $beginning_of_week = strtotime('last Monday',time()); 

if (date('w', time()) == 7)
    $end_of_week = strtotime('Today', time()) + 86400;
else 
    $end_of_week = strtotime('next Sunday', time()) + 86400;
Run Code Online (Sandbox Code Playgroud)