3
A
回答
2
沒有爲PHP中的DateTime::createFromImmutable()
方法拉請求,但它看起來像它一直沒有整合尚未:
https://www.reddit.com/r/PHP/comments/300tib/datetimecreatefromimmutable_method_php_7_merged/?st=iyac0id6&sh=8342be48
和https://github.com/php/php-src/pull/1145
因此,這可能是最簡單的方法現在:
$dateTime = new \DateTime();
$dateTime->setTimestamp($dateTimeImmutable->getTimestamp());
如果您需要包括時區信息:
$dateTime = new \DateTime(null, $dateTimeImmutable->getTimezone());
$dateTime->setTimestamp($dateTimeImmutable->getTimestamp());
0
你可以做到這一點作爲一個班輪:
$dateTime = new DateTime("@{$dateTimeImmutable->getTimeStamp()}");
相關問題
- 1. Convert Array to DayOfWeek
- 2. convert pointer to shared_ptr
- 3. convert model to viewmodel
- 4. convert inherited to generic base
- 5. Imagemagick convert pdf to png
- 6. unix convert long to wide
- 7. convert image to rgb code
- 8. Golang convert interface {} to struct
- 9. class sympy.core.add.Add convert to float
- 10. Javascript/convert json to csv
- 11. Python:How to convert .7z to .rar or .zip?
- 12. .NET DateTime to BizTalk DateTime
- 13. convert video/webm; codecs = vp9 to .flac
- 14. Doctrine2 Criteria convert 1 to TRUE
- 15. convert function to use css translate3d
- 16. convert zip byte [] to unzip byte []
- 17. boost :: asio convert socket to secure
- 18. convert * .txt content to codepage 850 OEM
- 19. Convert List <Object> to ByteArray
- 20. convert bumpbox(mootools)to use jQuery
- 21. convert double value 123.0 to 123.00
- 22. Convert 31-DEC-2016 to 2016-12-31
- 23. format varchar to datetime SQL Server 2008
- 24. Convert Date:Manip :: Obj to Time :: Piece or Class :: Date
- 25. Convert System.Collections.GenericList'1 [Newtonsoft.Json.Linq.JToken] List to Json Array c#
- 26. convert IQueryable <int> to <int>
- 27. CONVERT .AU文件TO .OGG文件
- 28. imagemagic convert .png to .gif高質量
- 29. convert type「system collection generic.iList <long> to long []」
- 30. 在swift中使用convert(_:to :)方法
這不「轉移」時區信息... –
@Glavić我編輯的答案:-) –
我會'新\日期時間($ immutable->格式(\日期時間:: ATOM))'。這是我現在可以想象的整潔和最少的數據丟失(時區等)。 –