簡體   English   中英

在PHP strtotime中使用術語“昨天”

[英]use of the term “yesterday” in php strtotime

我正在嘗試使用php strtotime函數獲取各天的時間戳,但是遇到了問題。 例如,嘗試獲取3月第二個星期日之前的日期和月份。

我已經運行了一些測試,並得到以下結果:

$day1 = date('j', strtotime('second sunday of march yesterday'));
$month1 = date('n', strtotime('second sunday of march yesterday'));

這將分別產生28和2,而不是7和3。

我將“昨天”一詞移到了上面,並得到以下信息:

$day1 = date('j', strtotime('yesterday second sunday of march'));
$month1 = date('n', strtotime('yesterday second sunday of march')); 

這確實會產生正確的結果,但是當我這樣做時

$day1 = date('j', strtotime('first sunday of november yesterday'));
$month1 = date('n', strtotime('first sunday of november yesterday'));

在這種情況下,在字符串的末尾加上“ yesterday”,它將產生正確的日期31和10。 即使“昨天”結束,也會產生此結果。

我想念什么嗎? 為什么其中之一需要“昨天”才能出現在字符串的開頭?

這不是yesterday -這是+- 1 day 由於某些原因, -1 day不起作用。

我不能說PHP在昨天做了什么,但是由於英文版本沒有意義,因此PHP對它的解釋也沒有意義也就不足為奇了。 ;)

暫無
暫無

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

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