Last active
January 30, 2016 18:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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