2016-04-22 54 views
-4

我正在觀察這個代碼,它是一個strtotime函數的php文件。請在下面的函數中告訴我'-1-1'的含義。strtotime()函數需要解釋,有人可以解釋這一行嗎?

的strtotime($一年。 '-1-1')

+0

當你想得到什麼結果? – Naumov

+1

將是文字 - ... Jan/01,例如,如果年份爲2016,則將返回01/01/2016的時間戳 – cmnardi

+1

使用strtotime()函數處理日期。閱讀http://php.net/manual/en/function.strtotime.php – sAcH

回答

0

strtotime()將您的字符串轉換爲Unix時間戳。

如:

strtotime("now") returns 1461336078 
strtotime("3 October 2005") returns 1128312000 
strtotime("+5 hours") returns 1461354078 and so on. 

在你的情況,你的時間字符串爲「2016年1月1日」,如果$一年= 2016也就是說,的strtotime($一年。' - 1 1' );將返回您在$ year變量中提供的任何一年中第一天的時間戳,方法是將您的年份與「-1-1」簡單地連接起來。

+0

謝謝。我希望我能夠升級它。這真的很有幫助。自一小時以來我一直困在這裏。 –

0

它串接到的任何$一年的結束日期的月份和日期..

如果$一年= 2016年,它的與寫作一樣strtotime('2016-1-1');