2015-11-19 29 views
1

我想知道爲什麼PHP DateTime類接受一個奇怪的值來表示時間戳嗎?

陌生人值是@{$timestamp}

例子:

$timestamp = time(); $date = new DateTime("@{$timestamp}");

PHP手冊並沒有顯示與@{$timestamp}任何信息!

請注意,這是不可能做這樣的事情: $date = new DateTime(time());

我知道來設置DateTime類時間戳最簡單的方法是:$date->setTimeStamp(time());但我問@{$timestamp}

有誰知道@{$timestamp}背後的魔法是什麼?

+0

'$日期=新的DateTime();'將是無效'$日期=新日期時間的當量(time()的);'因爲默認是當前時間 –

回答

2

@timestamp使用是documentedDate/Time>Supported Date and Time Formats>Compound Formats>Localized Notations

Description Format   Examples 

Unix Timestamp "@" "-"? [0-9]+ "@1215282385" 
相關問題