php获取各种时间戳

直接看代码就知道啥意思了!

<?php

// 获取明天凌晨时间戳:
echo "今天凌晨的时间戳:" . strtotime(date("Y-m-d")) . PHP_EOL;

echo "一天后:" . date("Y-m-d", strtotime("+1 day")) . PHP_EOL;

echo "一周后:" . date("Y-m-d", strtotime("+1 week")) . PHP_EOL;

echo "一周零两天四小时两秒后:" . date("Y-m-d G:H:s", strtotime("+1 week 2 days 4 hours 2 seconds")) . PHP_EOL;

echo "下个星期四:" . date("Y-m-d", strtotime("next Thursday")) . PHP_EOL;

echo "上个周一:" . date("Y-m-d", strtotime("last Monday")) . PHP_EOL;

echo "一个月前:" . date("Y-m-d", strtotime("last month")) . PHP_EOL;

echo "一个月后:" . date("Y-m-d", strtotime("+1 month")) . PHP_EOL;

echo "十年后:" . date("Y-m-d", strtotime("+10 year")) . PHP_EOL;


//如果需要的是时间戳,那就更简单了:

echo strtotime("now"), "\n";

echo strtotime("+0 day"), "\n";

echo strtotime("10 September 2000"), "\n";

echo strtotime("+1 day"), "\n";

echo strtotime("+1 week"), "\n";

echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";

echo strtotime("next Thursday"), "\n";

echo strtotime("last Monday"), "\n";

//昨天
print date('Y-m-d', strtotime('-1 day')) . PHP_EOL;
//上星期
print date('Y-m-d', strtotime('-1 week')) . PHP_EOL;
//上个月
print date('Y-m-d', strtotime('-1 month')) . PHP_EOL;
//去年
print date('Y-m-d', strtotime('-1 year')) . PHP_EOL;

怎么样,是不是很有用处!

看看效果:
这里写图片描述

补充–2018.3.19

#上周一
$data = date('Y-m-d H:i:s', strtotime('-1 monday'));
#下周一
$data = date('Y-m-d H:i:s', strtotime('+2 monday'));

#计算生日
function birthday2($birthday)
{
    list($year, $month, $day) = explode("-", $birthday);
    $year_diff = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff = date("d") - $day;
    if ($day_diff < 0 || $month_diff < 0) {
        $year_diff--;
    }
    return $year_diff;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值