Forum Moderators: coopster
i'm looking at a date information (which comes as a string!) and i would like to modify it to look nice in "german" format.
the original string looks like this:
2/27/05 3:00 PM Local Time
and i would like that one to be replaced by
27.2.05, 15:00 Uhr
so a little preg_replacing needs to be done i guess and something smart to convert the am/pm-time-format to 24h format................
THX FOR YOUR HELP!
$date = '2/27/05 3:00 PM Local Time ';
$pattern = "/(\d{1,2})\/(\d{1,2})\/(\d{2})\b/";
$replace = "$2.$1.$3";
$newDate = preg_replace($pattern, $replace, $date);
The date you have there is a valid GNU Date Input Format [gnu.org] for the strtotime() [php.net] function, but you'll have to strip that 'Local Time' part off first.
$time = '2/27/05 3:00 PM Local Time';
$time = str_replace [php.net](' Local Time', '', $time);
$timestamp = strtotime [php.net]($time);
$formattedtime = strftime [php.net]('%d.%m.%y %H:%M Uhr', $timestamp);
$formattedtime = preg_replace [php.net]("/\.0(\d)\./", ".$1.", $formattedtime);
print "\$formattedtime: $formattedtime";