Search code examples
phpdatetimeisodate

How to add one second to ISO date time string in PHP


I have date time string 2016-05-31T00:42:11.578Z I want to add one second to it so it will look like 2016-05-31T00:42:12.578Z.
How I can add one second to ISO date, thanks in advance.


Solution

  • Check out PHP's DateTime and DateInterval classes:

    $date = new DateTime("2016-05-31T00:42:11.578Z");
    $date->add(new DateInterval("PT1S"));