From 49ae01e05ef5a68ad0d22f5b73992149409434a2 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sat, 9 Jan 2016 20:44:22 +0100 Subject: Initial commit --- PHP/functions/parseDatetime.php | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 PHP/functions/parseDatetime.php (limited to 'PHP') diff --git a/PHP/functions/parseDatetime.php b/PHP/functions/parseDatetime.php new file mode 100644 index 0000000..bce498b --- /dev/null +++ b/PHP/functions/parseDatetime.php @@ -0,0 +1,51 @@ + 'January', + '02' => 'February', + '03' => 'March', + '04' => 'April', + '05' => 'May', + '06' => 'June', + '07' => 'July', + '08' => 'August', + '09' => 'September', + '10' => 'October', + '11' => 'November', + '12' => 'December' + ]; + + $days = [ + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday' + ]; + + return strtr($format, [ + '[Y]' => $year, + '[M]' => $month, + '[D]' => $day, + '[H]' => $hour, + '[I]' => $minute, + '[S]' => $second, + '[W]' => $days[date('w', strtotime($datetime))], + '[F]' => $months[date('m', strtotime($datetime))] + ]); +} + +#=============================================================================== +# EXAMPLE: +#=============================================================================== +echo parseDatetime('2015-10-25 12:24:32', '[W], [D]. [F] [Y] at [H]:[M]'); +?> \ No newline at end of file -- cgit v1.2.3