簡體   English   中英

如何在PHP中獲得當前月份的前3個月

[英]how to get the previous 3 months with the current month in php

如何在php中獲得當前月份的前3個月?

像這樣

mktime(0, 0, 0, date("m")); //it's 00:00 first day of current month
mktime(0, 0, 0, date("m")-1); //it's 00:00 first day of previous month
mktime(0, 0, 0, date("m")-2); //it's 00:00 first day 2 month before 
mktime(0, 0, 0, date("m")-3); //it's 00:00 first day 3 month before

該函數返回unix時間戳,並可以用date函數格式化。

您將需要閱讀有關函數的信息: date()mktime()

這可以通過應用PHP的字符串時間方法來完成

$lastMonth = date('m', strtotime('last month'));
$twoMonthsAgo = date('m', strtotime('-2 months'));
$threeMonthsAgo = date('m', strtotime('-3 months'));

您可以在此處閱讀有關strtotime的更多信息: http ://www.php.net/strtotime

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM