Skip to content

Instantly share code, notes, and snippets.

@der-On
Created June 28, 2013 12:48
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 der-On/5884431 to your computer and use it in GitHub Desktop.
Save der-On/5884431 to your computer and use it in GitHub Desktop.
DateUtil
<?php
class DateUtil
{
public static $weekday_names = array(
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag',
0 => 'Sonntag'
);
public static $weekday_names_short = array(
1 => 'Mo',
2 => 'Di',
3 => 'Mi',
4 => 'Do',
5 => 'Fr',
6 => 'Sa',
0 => 'So'
);
public static $month_names = array(
0 => 'Januar',
1 => 'Februar',
2 => 'März',
3 => 'April',
4 => 'Mai',
5 => 'Juni',
6 => 'Juli',
7 => 'August',
8 => 'September',
9 => 'Oktober',
10 => 'November',
11 => 'Dezember'
);
public static $month_names_short = array(
0 => 'Jan',
1 => 'Feb',
2 => 'März',
3 => 'Apr',
4 => 'Mai',
5 => 'Jun',
6 => 'Jul',
7 => 'Aug',
8 => 'Sep',
9 => 'Okt',
10 => 'Nov',
11 => 'Dez'
);
public static function getWeek($time = NULL)
{
if(!isset($time)) $time = time();
return intval(date('W',$time));
}
public static function getMonthName($time = NULL)
{
if(!isset($time)) $time = time();
$month = intval(date('n',$time))-1;
return self::$month_names[$month];
}
public static function getMonthNameShort($time = NULL)
{
if(!isset($time)) $time = time();
$month = intval(date('n',$time))-1;
return self::$month_names_short[$month];
}
public static function getWeekDay($time = NULL)
{
if(!isset($time)) $time = time();
$day = intval(date('w',$time));
return $day;
}
public static function getWeekDayName($time = NULL)
{
return self::$weekday_names[self::getWeekDay($time)];
}
public static function getWeekDayNameShort($time = NULL)
{
return self::$weekday_names_short[self::getWeekDay($time)];
}
public static function getYearStartTime($time = NULL)
{
if(empty($time)) {
$time = time();
}
$strtotime = '1-1-'.date("Y",$time);
$start = strtotime($strtotime);
return $start;
}
public static function getMonthStartTime($time = NULL)
{
if(empty($time)) {
$time = time();
}
$strtotime = date("o-\mm",$time);
$start = strtotime($strtotime);
return $start;
}
public static function getWeekStartTime($time = NULL)
{
if(empty($time)) {
$time = time();
}
$strtotime = date("o-\WW",$time);
$start = strtotime($strtotime);
return $start;
}
public static function getDayStartTime($time = NULL)
{
if(empty($time)) {
$time = time();
}
$day = intval(date('z',$time));
$start = strtotime(date('Y-m-d',$time));
return $start;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment