1

I'm trying to parse the following ISO 8601 date in PHP 4 using the strtotime function:

2012-02-01T00:00:00.000Z

However this returns -1. How come and what can I do to work around this?

Unfortunately I'm stuck using PHP 4.3.10 and so can't use any of the newer functions to parse dates.

Theodore R. Smith
  • 21,848
  • 12
  • 65
  • 91
Justin
  • 84,773
  • 49
  • 224
  • 367
  • Not helpful, but: PHP 5 has been out for nearly 8 years now. Probably time to unstick yourself :P – Hamish Feb 24 '12 at 09:40

2 Answers2

1

That works for me:

$iso = '2013-06-25T15:16:13.000Z';
$d = str_replace('T', ' ', $iso);
$d = substr($d, 0, 19);
$ts = strtotime($d);

$isIso =  (strlen($iso) == 24 && substr($iso, 10, 1) === "T" && substr($iso, 19, 1) === "." && substr($iso, 23, 1) === "Z");
dltest1
  • 11
  • 1
1

Try this:

strtotime(str_replace('T', ' ', $date));
Justin
  • 84,773
  • 49
  • 224
  • 367
Theodore R. Smith
  • 21,848
  • 12
  • 65
  • 91
  • This still returns -1. Some experimentation reveals that it parses the string `2012-02-01T00:00:00`, I'm just not sure how to detect that the date is in that format. – Justin Feb 24 '12 at 09:33