Har udvidet en klasse jeg tidligere har skrevet her på udvikleren:
<?php
class Date
{
/**
* @param {string} $strDate Date to use with this object. Can be any given date (defaults to today).
*/
function __construct($strDate = NULL) {
$this->strDate = $strDate == NULL ? date('d-m-Y H:i:s') : $strDate;
}
function parse() {
return strtotime($this->strDate);
}
function getYear() {
return date('Y',$this->parse());
}
function getMonth() {
return date('n',$this->parse());
}
function getDay() {
return date('d',$this->parse());
}
function getDate($format = 'd. F Y') {
$langMonth = array("Januar", "Febuar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December" );
$date['F'] = $langMonth[($this->getMonth()-1)];
$date['d'] = $this->getDay();
$date['Y'] = $this->getYear();
return str_replace(
array('d','F','Y'),
array($date['d'],$date['F'],$date['Y']),
$format);
}
/**
* @param {string} $format
*/
function getFirstDayInMonth($format = 'l') {
$month = date('m',$this->parse());
$year = date('Y',$this->parse());
return date($format,mktime(0, 0, 0, $month, $format === 'l' ? 0 : 1, $year));
}
}
// Usage
$d = new Date();
print $d->getDate();
print $d->getFirstDayInMonth('l');
?>