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. SQL Server datetime convert
- 2. Convert Array to DayOfWeek
- 3. convert pointer to shared_ptr
- 4. Convert double [] to long []
- 5. convert model to viewmodel
- 6. Convert Subject to Observable
- 7. convert class to parcelable
- 8. convert .xls to .csv java
- 9. class sympy.core.add.Add convert to float
- 10. Golang convert interface {} to struct
- 11. Imagemagick convert pdf to png
- 12. convert datatable to listview vb.net
- 13. c#convert system.IO.Stream to Byte []
- 14. Convert For Loop to Haskell
- 15. Mono.Cecil convert .exe to dll?
- 16. android - convert dp to float
- 17. Javascript/convert json to csv
- 18. convert inherited to generic base
- 19. Convert Time.now to Date - Elm
- 20. convert varchar to bigint function
- 21. unix convert long to wide
- 22. convert image to rgb code
- 23. Python:How to convert .7z to .rar or .zip?
- 24. .NET DateTime to BizTalk DateTime
- 25. convert function to use css translate3d
- 26. convert zip byte [] to unzip byte []
- 27. boost :: asio convert socket to secure
- 28. Convert List <Object> to ByteArray
- 29. convert ArrayList <Object[]> to Object []
- 30. convert video/webm; codecs = vp9 to .flac
這不「轉移」時區信息... –
@Glavić我編輯的答案:-) –
我會'新\日期時間($ immutable->格式(\日期時間:: ATOM))'。這是我現在可以想象的整潔和最少的數據丟失(時區等)。 –