Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active January 30, 2016 18:44
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 finalwebsites/5cb2108a5db0d1af9c7c to your computer and use it in GitHub Desktop.
Save finalwebsites/5cb2108a5db0d1af9c7c to your computer and use it in GitHub Desktop.
PHP local date notations - This simple class is an 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.
<?php
class local_date {
private $week_day;
private $day;
private $month;
private $year;
public function __construct() {
$this->week_day = date("l");
$this->day = date("j");
$this->month = date("n");
$this->year = date("Y");
}
//translate in your local language
public 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];
}
public function get_month() {
$nl_month = array("1" => "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "october", "november", "december");
return $nl_month[$this->month];
}
public function build_date() {
$long_date = $this->day." ".$this->get_month()." ".$this->year;
return $long_date;
}
}
// How to use?
$my_date = new local_date();
echo $my_date->get_day().", ".$my_date->build_date();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment