It should work for most basic formats, however you should improve this function if you need more complex formats.
Timezones and DST are not supported, but if you just need compatible basic functions this works. If you are using 'single' speech marks around the format string, then you only need one backslash. A good way I did to work with millisecond is transforming the time in milliseconds.
Bug report has unfortunately be closed as "not a bug" even though it's a clear violation of the ISO standard. Version Description 7. You can create a DateTime with fractional seconds and retrieve that value using the 'u' format string.
The datetime class
At PHP 7. It seems like you can create a timezone object like 'EDT' but can't use those to set timezones properly. This is a great class, but unless you need to use it's more advanced features, I would stick to passing times around your scripts as Unix Time Stamps - maybe prefixing with "uts".
DateTime supports microseconds since 5. If you need to be strictly compliant to that standard you will have to write your own format.
Changelog Version Description 7. This caused some confusion with a blog I was working on and just wanted to make other people aware of this.
The process, however does act like it's working without errors. This is mentioned in the documentation for the date function, but bears repeating here. This will not give you the result you were expecting.
If you're stuck on a PHP 5. This class behaves the same as DateTimeImmutable except objects are modified itself when modification methods such as DateTime::modify are called.
But if in the some reason, some server setup not have 'DateTime' enabled, it will use simple but not safe calculation with 'strtotime '. Set Timezone and formatting.
Note that the ISO constant will not correctly parse all possible ISO compliant formats, as it does not support fractional seconds. If you have timezone information in the time string you construct the DateTime object with, you cannot add an extra timezone in the constructor. Feel free to complete this so it's compatible with the 5.
Make your comparisons carefully, since two DateTime objects constructed one after another are now more likely to have different values. It isn't obvious from the above, but you can insert a letter of the alphabet directly into the date string by escaping it with a backslash in the format string.
Table of contents
Submit a Pull Request Report a Bug. Class synopsis. Note that if you are using "double" speech marks around the format string, you will have to further escape each backslash with another backslash!
Otherwise you will simply be creating more lines of code with no benefit. DateTime::add ». If you use createFromFormat to turn a date into a timestamp it will include the current time.