Php datetime createfromformat iso 8601

Nobody mentioned to use DATE_ATOM which is as far as i know phps most correct implementation of ISO 8601. It should at least work for the last 3 of these:


To be able to parse all of them i wrote a tiny function:


As @Glutexo mentioned it works only if there are only 1 to 6 precision digits for the decimal part, too. Feel free to improve it.

PHP DateTime class – parsing and formatting ISO8601 dates with or w/o fractions of a second

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

Chủ Đề