Zend - The PHP Company




Conversion

Add Code


PHP Local date  

Type: class
Added by: olaflederer
Entered: 11/01/2005
Last modified: 01/12/2004
Rating: - (fewer than 3 votes)
Views: 4000
I replaced the old code snippet with this simple class. This class (my first one, only for testing) is more flexible and can be used for date calculations. You need to translate the week-days and month names in your local language. This is the last release because some simple PHP functions do the same job.


<?php
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;
    }
}
?>


Usage Example


$my_date = new local_date;
echo $my_date->get_day().", ".$my_date->build_date();
// this will output "Woensdag, 7 juli 2004" 


Rate This Script





Search



This Category All Categories