class dateTimeConverter
{
public static function getGermanDay( $timestamp, $long = TRUE )
{
if( $long )
$days = array( "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" );
else
$days = array( "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa" );
$day = date( "w", $timestamp );
return $days[$day];
}
public static function getGermanMonth( $timestamp, $maxLetters = 9 )
{
$monthInt = date( "n", $timestamp );
if( $maxLetters == 3 )
{
$months = array( "Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" );
return $months[$monthInt-1];
}
elseif( $maxLetters == 4 )
{
$months = array( "Jan.", "Feb.", "März", "Apr.", "Mai", "Juni", "Juli", "Aug.", "Sept.", "Okt.", "Nov.", "Dez." );
return $months[$monthInt-1];
}
else
{
$months = array( "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" );
return substr( $months[$monthInt-1], 0, $maxLetters );
}
}
public static function getGermanDate( $timestamp )
{
$weekday = dateTimeConverter::getGermanDay( $timestamp );
$day = date( "d", $timestamp );
$month = dateTimeConverter::getGermanMonth( $timestamp );
$year = date( "Y", $timestamp );
return $weekday . ", " . $day . " " . $month . " " . $year;
}
public static function convertDateFromDB( $date ) // date from database to german
{
$jahr = substr( $date, 0, 4 );
$mon = substr( $date, 5, 2 );
$tag = substr( $date, 8, 2 );
return $tag . "." . $mon . "." .$jahr;
}
public static function convertDateForDB( $date, $delimiter ="." ) // date for database (from d.m.Y to Y-m-d)
{
if( empty( $delimiter ) )
return false;
else {
$dateArray = explode( $delimiter, $date );
if( count( $dateArray ) == 3 ) // day, month and year
return $dateArray[2] . "-" . $dateArray[1] . "-" . $dateArray[0];
else
return false;
}
}
public static function createUnixTimestamp( $date, $hour = 0, $minute = 0 ) // timestamp from database
{
$year = substr( $date, 0, 4 );
$month = substr( $date, 5, 2 );
$day = substr( $date, 8, 2 );
return mktime( $hour, $minute, 0, $month, $day, $year );
}
function getOnlyTimeFromDB( $db_timestamp ) // deutsche Uhrzeit aus Datenbank-Eintrag extrahieren
{
return substr( $db_timestamp, 10 );
}
}