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.
$parts = explode('-', $yourString);
$parts[0]++;
$yourString = $parts[0] . '-' . $parts[1];
$parts[0] = str_pad($parts[0], 2, '0', STR_PAD_LEFT);
$parts[1] = str_pad($parts[1], 2, '0', STR_PAD_LEFT);
$yourString = $parts[0] . '-' . $parts[1];
function getNumberOfWeeksInYear($year) {
return int_val(gmdate("W", strtotime("31 December $year")));
}
Hallo,Habe gerade hier eine Lösung für dich gefunden: http://stackoverflow.com/a/3319413/603003
PHP:function getNumberOfWeeksInYear($year) { return int_val(gmdate("W", strtotime("31 December $year"))); }
function formatWeek ($string) {
if (sscanf($string, '%d-%d', $week, $year) !== 2) {
return false;
}
if ($week === (int) date('W', mktime(0, 0, 0, 1, 1, $year + 1))) {
return sprintf('%d-%d', 1, $year + 1);
} else {
return sprintf('%d-%d', $week + 1, $year);
}
}
function year_has_53_weeks ($year) {
$first = (int) date('N', mktime(0, 0, 0, 1, 1, $year));
$last = (int) date('N', mktime(0, 0, 0, 12, 31, $year));
return (($first === 4 and ($last === 4 or $last === 5)) or ($first === 3 and $last === 4));
}
# und die eigentliche Funktion
function formatWeek ($string) {
if (sscanf($string, '%d-%d', $week, $year) !== 2) {
return false;
}
if (year_has_53_weeks($year) xor $week === 52) {
return sprintf('%d-%d', 1, $year + 1);
} else {
return sprintf('%d-%d', $week + 1, $year);
}
}
//$week_before = explode("-", $label_x[$j-1]);
// For testing: 2015 has 53 weeks; 2014 has 52
$week_before[0] = '52';
$week_before[1] = '15';
echo '$week_before[0] = '.$week_before[0].' // week<br> ';
echo '$week_before[1] = '.$week_before[1].' // year<br><br>';
if ($week_before[0] < 52) {
$week = str_pad(($week_before[0] + 1),2,'0',STR_PAD_LEFT);
$year = str_pad(($week_before[1]),2,'0',STR_PAD_LEFT);
}
elseif ($week_before[0] == 52) {
// is it a 53-week year? this is only the case if the fist AND the last day are Thursdays.
$first_day = mktime(0, 0, 0, 1, 1, '20'.$week_before[1]);
$last_day = mktime(0, 0, 0, 12, 31, '20'.$week_before[1]);
/*print date("Y-m-d H:i:s", $first_day)." --> ";
print date("N", $first_day);
print '<br>';
print date("Y-m-d H:i:s", $last_day)." --> ";
print date("N", $last_day);*/
if ((date("N", $first_day) == 4) AND (date("N", $first_day) == 4)) {
$week = '53';
$year = str_pad(($week_before[1]),2,'0',STR_PAD_LEFT);
}
else {
$week = '01';
$year = str_pad(($week_before[1] + 1),2,'0',STR_PAD_LEFT);
}
}
elseif ($week_before[0] == 53) {
$week = '01';
$year = str_pad(($week_before[1] + 1),2,'0',STR_PAD_LEFT);
}
else {
die("error in week computation");
}
echo '$week = '.$week.'<br>';
echo '$year = '.$year;
die();
date('W', mktime(0, 0, 0, 12, 28, $year)) === '53';