note 109035 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Thu, 14 Jun 2012 17:39:57 +0000 |
| Subject: | note 109035 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188615@lists.php.net to get a copy of this message | ||
Here is a cool Date class to implement the date
function: <?php /* *
@author	Gchats * * Date class
*/ class Date {	 	private
$shortDateFormat = "F j, Y"; 	private $longDateFormat =
"F j, Y, g:i a"; 	private $timestamp =
0; 	 	/** 	* Default
constructor 	* 	*
@param	integer		$timestamp	unix time
stamp 	*/ 	function __construct($timestamp =
0) 	{ 		$this->timestamp =
$timestamp; 	} 	 	/** 	*
Returns the given timestamp in the constructor 	* 	*
@return	integer		time
stamp 	*/ 	public function
getTime() 	{ 		return (int)
$this->timestamp; 	} 	 	/* 	
* Returns long formatted date of the given timestamp 	
* 	 * @access public 	 * @return
	string	Long formatted date 	
*/ 	public function
long() 	{ 		if ( $this->timestamp
> 0 ) 		{ 			return
date ( $this->longDateFormat , $this->timestamp
); 		} 		else 		{ 			return
""; 		} 	} 	/* 	
* Returns short formatted date of the given timestamp 	
* 	 * @access public 	 * @return
	string	Short formatted date 	
*/	 	public function
short() 	{ 		if ( $this->timestamp
> 0 ) 		{ 			return
date ( $this->shortDateFormat , $this->timestamp
); 		} 		else 		{ 			return
""; 		} 	} 	 	public
function __toString() 	{ 		return
$this->timestamp; 	} 	 } ?>
--was--
Here is a cool Date class to implement the date function:
<?php
/*
* @author Gchats http://www.gchats.com
*
* Date class
*/
class Date
{
private $shortDateFormat = "F j, Y";
private $longDateFormat = "F j, Y, g:i a";
private $timestamp = 0;
/**
* Default constructor
*
* @param integer $timestamp unix time stamp
*/
function __construct($timestamp = 0)
{
$this->timestamp = $timestamp;
}
/**
* Returns the given timestamp in the constructor
*
* @return integer time stamp
*/
public function getTime()
{
return (int) $this->timestamp;
}
/*
* Returns long formatted date of the given timestamp
*
* @access public
* @return string Long formatted date
*/
public function long()
{
if ( $this->timestamp > 0 )
{
return date ( $this->longDateFormat , $this->timestamp );
}
else
{
return "";
}
}
/*
* Returns short formatted date of the given timestamp
*
* @access public
* @return string Short formatted date
*/
public function short()
{
if ( $this->timestamp > 0 )
{
return date ( $this->shortDateFormat , $this->timestamp );
}
else
{
return "";
}
}
public function __toString()
{
return $this->timestamp;
}
}
?>
http://php.net/manual/en/function.date.php