This class is a great example on how-to create an object for simple tasks like a date notation. Sure there are many ways to handle your local date notations, but this "mini class" is a great example to learn how a class works. This class has methods for week day and month name translations (in this case the Dutch date names). Just translate the week days and month names in your local language and you're done.
class local_date { var $week_day; var $day; var $month; var $year; function local_date() { //constructor $this->week_day = date("l"); $this->day = date("j"); $this->month = date("n"); $this->year = date("Y"); } //translate in local language function get_day() { $nl_day = array("Monday" => "Maandag", "Tuesday" => "Dinsdag", "Wednesday" => "Woensdag", "Thursday" => "Donderdag", "Friday" => "Vrijdag", "Saturday" => "Zaterdag", "Sunday" => "Zondag"); return $nl_day[$this->week_day]; } function get_month() { $nl_month = array("1" => "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "october", "november", "december"); return $nl_month[$this->month]; } function build_date() { $long_date = $this->day." ".$this->get_month()." ".$this->year; return $long_date; } }
How-to use this object in your script or application?
echo "hello world"; $my_date = new local_date; echo $my_date->get_day().", ".$my_date->build_date(); // this will output "Woensdag, 7 juli 2004"
If you're looking for native php function for a localized date notation check the php function
setlocale.