shockshell
Erfahrenes Mitglied
Wie lautet denn die Meldung?
Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
function parseDateByFormat($date, $format)
{
$timestamp = null;
$formatPatterns = array(
'a' => '(?P<a>am|pm)',
'A' => '(?P<A>AM|PM)',
'B' => '(?P<B>[0-9]{3})',
// 'c' => '(?P<c>)',
'd' => '(?P<d>[1-9]|[12][0-9]|3[01])',
'D' => '(?P<D>Mon|Tue|Wed|Thu|Fri|Sat|Sun)',
'F' => '(?P<F>January|February|March|April|May|June|July|August|September|October|November|December)',
'g' => '(?P<g>[1-9]|1[0-2])',
'G' => '(?P<G>[0-9]|1[0-9]|2[0-3])',
'h' => '(?P<h>0[1-9]|1[0-2])',
'H' => '(?P<H>[01][0-9]|2[0-3])',
'i' => '(?P<i>[0-4][0-9]|5[0-9])',
'I' => '(?P<I>[01])',
'j' => '(?P<j>[1-9]|[12][0-9]|3[01])',
'l' => '(?P<l>Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)',
'L' => '(?P<L>[01])',
'm' => '(?P<m>0[1-9]|1[0-2])',
'M' => '(?P<M>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)',
'n' => '(?P<n>[1-9]|1[0-2])',
'O' => '(?P<O>[+\-][0-9]{4})',
// 'r' => '(?P<r>)',
's' => '(?P<s>[0-4][0-9]|5[0-9])',
'S' => '(?P<S>st|nd|rd|th)',
't' => '(?P<t>28|29|30|31)',
'T' => '(?P<T>[A-Z]{3})',
'U' => '(?P<U>[1-9][0-9]*)',
'w' => '(?P<w>[0-6])',
'W' => '(?P<W>[1-9]|[1-4][0-9]|5[0-3])',
'Y' => '(?P<Y>[0-9]{4})',
'y' => '(?P<y>[0-9]{2})',
'z' => '(?P<z>[0-9]|[12][0-9][0-9]|3(?:[0-5][0-9]|6[0-5]))',
'Z' => '(?P<Z>-?(?:[0-9]|[1-9][0-9]{3}|[1-3][0-9]{4}|4(?:[0-2][0-9]{3}|3[01][0-9]{2}|3200)))',
);
$regexp = preg_replace('/[a-zA-Z]/e', 'isset($formatPatterns["$0"])?$formatPatterns["$0"]:"$0"', $format);
if (preg_match('/^'.$regexp.'$/', trim($date), $match)) {
$values = array(0, 0, 0, 0, 0, 0, 0);
foreach ($match as $format => $value) {
if ($format == 'g' || $format == 'G' || $format == 'h' || $format == 'H') {
$values[0] = $value;
} else if ($format == 'i') {
$values[1] = $value;
} else if ($format == 's') {
$values[2] = $value;
} else if ($format == 'm' || $format == 'n') {
$values[3] = $value;
} else if ($format == 'd' || $format == 'j') {
$values[4] = $value;
} else if ($format == 'Y' || $format == 'y') {
$values[5] = $value;
}else if($format=='F'){
switch($value){
case 'January':
$values[3]=1;
break;
case 'February':
$values[3]=2;
break;
case 'March':
$values[3]=3;
break;
case 'April':
$values[3]=4;
break;
case 'May':
$values[3]=5;
break;
case 'June':
$values[3]=6;
break;
case 'July':
$values[3]=7;
break;
case 'August':
$values[3]=8;
break;
case 'September':
$values[3]=9;
break;
case 'October':
$values[3]=10;
break;
case 'November':
$values[3]=11;
break;
case 'December':
$values[3]=12;
break;
}
}
}
$timestamp = mktime($values[0], $values[1], $values[2], $values[3], $values[4], $values[5]);
}
return $timestamp;
}
$time=parseDateByFormat('March 10, 2001, 5:16 pm', 'F j, Y, g:i a');
echo date('d.m.Y H:i:s',$time);