久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從日期中減去一定數量的小時、天、月或年

Subtracting a certain number of hours, days, months or years from date(從日期中減去一定數量的小時、天、月或年)
本文介紹了從日期中減去一定數量的小時、天、月或年的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試創建一個簡單的函數,它返回一個從現在開始減去一定天數的日期,所以類似這樣的事情,但我不太了解日期類:

I'm trying to create a simple function which returns me a date with a certain number of subtracted days from now, so something like this but I dont know the date classes well:

<?
function get_offset_hours ($hours) {
    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
}

function get_offset_days ($days) {
    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
}

function get_offset_months ($months) {
    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
}

function get_offset_years ($years) {
    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") + $years));
}

print get_offset_years (-30);
?>

有沒有可能做類似的事情?這種功能可以用很多年,但是其他時間類型怎么做呢?

Is it possible to do something similar to this? this kind of function works for years, but how to do the same with other time types?

推薦答案

幾個小時:

function get_offset_hours($hours)
{
    return date('Y-m-d H:i:s', time() + 3600 * $hours);
}

這樣的東西可以在數小時和數天內正常工作(使用 86400 數天),但對于數月和數年,它有點棘手......

Something like that will work well for hours and days (use 86400 for days), but for months and year it's a bit trickier...

你也可以這樣做:

$date = strtotime(date('Y-m-d H:i:s') . ' +1 day');
$date = strtotime(date('Y-m-d H:i:s') . ' +1 week');
$date = strtotime(date('Y-m-d H:i:s') . ' +2 weeks');
$date = strtotime(date('Y-m-d H:i:s') . ' +1 month');
$date = strtotime(date('Y-m-d H:i:s') . ' +30 days');
$date = strtotime(date('Y-m-d H:i:s') . ' +1 year');

echo(date('Y-m-d H:i:s', $date));

這篇關于從日期中減去一定數量的小時、天、月或年的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 全部免费毛片在线播放网站 | 天天草天天操 | 久久亚洲一区二区三区四区 | 婷婷久久综合 | 在线免费看黄 | 精品一区二区在线看 | 精品国产乱码久久久久久蜜臀 | 韩日有码 | 亚洲成人一区二区 | 日韩精品a在线观看图片 | 国产一级片在线播放 | 色综合久| 日韩激情视频一区 | 午夜久草 | 久久国内精品 | 亚洲天堂男人的天堂 | av日韩一区 | 成人在线视频免费观看 | 亚洲一区在线日韩在线深爱 | 亚洲精品久久久久国产 | 久久久影院 | 久久精品欧美一区二区三区不卡 | 亚洲国产精品va在线看黑人 | 欧美精品在线播放 | 丁香婷婷久久久综合精品国产 | 国产成人精品午夜视频免费 | 水蜜桃久久夜色精品一区 | 波多野结衣av中文字幕 | 亚洲天堂中文字幕 | a级性视频| 91在线视频国产 | 国产精品国产成人国产三级 | 黄色在线免费观看视频 | 99精品国产一区二区青青牛奶 | 久久一二三区 | 91久久| 国产一区二区三区四区区 | 中文福利视频 | 成人精品一区亚洲午夜久久久 | 国产精品日产欧美久久久久 | 亚洲精彩视频在线观看 |