Skip to content

Instantly share code, notes, and snippets.

@maxflex
Last active February 11, 2016 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxflex/0c1b1f3413e5d49ed699 to your computer and use it in GitHub Desktop.
Save maxflex/0c1b1f3413e5d49ed699 to your computer and use it in GitHub Desktop.
Here
<?php
function formatDate($date) {
$date = preg_replace('/:|T|\.|\+/', '-', $date);
$p = explode('-', $date);
foreach ($p as $index => &$part) {
if ($index == 6) {
$part .= str_repeat('0', 7 - strlen($part));
} else {
$part = strlen($part) < 2 ? 0 . $part : $part;
}
}
return "$p[0]-$p[1]-$p[2]T$p[3]:$p[4]:$p[5].$p[6]+$p[7]:$p[8]";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment