【问题标题】:get start time of yesterday in unix time stamp(php) [duplicate]在unix时间戳(php)中获取昨天的开始时间[重复]
【发布时间】:2016-12-26 08:20:20
【问题描述】:

如何获取 Unix 时间戳格式的昨天时间?

例如,我想获取昨天的开始时间:

2016:12:25 00:00:00

【问题讨论】:

    标签: php unix-timestamp strtotime


    【解决方案1】:

    这将为您提供昨天的时间

    昨天的日期

    echo "Yesterday date".time() - 86400; //this will take current time
    

    给定日期的最后一天

    $inputedDate = "2016:12:25 00:00:00"; // you can pass date you want
    $yesterdayDate = date ("Y-m-d H:i:s",strtotime($inputedDate)-86400);
    echo $yesterdayDate;
    

    【讨论】:

    • 这在时钟切换时不起作用,因为有时您可能会多出一个小时或错过一个小时。
    【解决方案2】:

    您只需在格式后将 strtotime('-1 day', strtotime('datetime')) 传递给您的 date() 函数即可将其减去 1 天

    echo date( 'U', strtotime('-1 day', strtotime('2016:12:25 00:00:00')) );
    

    DEMO

    【讨论】:

    猜你喜欢
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2015-11-18
    相关资源
    最近更新 更多