簡體   English   中英

在PHP中,不管您是當月的哪個月的哪一天,獲取上個月最后一天的最有效方法是什么?

[英]In PHP what is the most efficent way to get the last day of the previous month, regardless of what day of the month in the current month you are?

我需要能夠將上個月的最后一天轉換為日期變量。 該腳本可以在當月的任何一天運行。 即使上個月的最后一天是29,30,31等,它也需要動態調整。

最好的日子是什么?

我將提供一種方法,使所有重復項均不被提及。 mktime支持超出范圍的值,因此,如果您要求提供7/40/2010,它將提供給您8/9/2010; 您可以將其取反,並要求當月的第0天獲得上一個的最后一天:

$lastDayTimestamp = mktime(0, 0, 0, date('n'), 0);

暫無
暫無

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

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