Jump to content

Time::Stamp() class I wrote


Augury

Recommended Posts

It's got two basic features.  First it produces an array to be array_merged prior to mysql entry.  The time is sort worthy as is (year in front ... last seconds).  100% collation friendly.

 

Second it prints the time in the conventional manor so that your reports are not criticized by all.  You can alter the thing to you choice of display formating if you like other wise you have to specify a format (hopefully you have a list of preferred formats already made up).  The print will also accept an appropriately formated input, this I've set to the mysql  timestamps format.

 

http://CampKojak.com/Time.php

 

I tried to make it look nice.

class Time {
 public static function now ($zone = NULL) {
		$format = '%Y-%m-%d %H:%M:%S';
		$strf = strftime($format);
		if(isset($zone)) $zone = " " . $zone;
		$strf .= $zone;
		return $strf;
 }

 public static function Stamp ($zone = NULL) {
	$timestamp = array("timestamp" => self::now($zone));
	return $timestamp;
 }


 public static function PPrint ($zone = NULL, $stamp = NULL,
  $formatin = "Y-m-d H:i:s T", $formatout = "g:i a l n/j/Y")
 {
 		if(empty($zone))  {$zone = date_default_timezone_get();}
		if(empty($stamp))  {$stamp = self::Stamp($zone);}
	 	$adate = DateTime::createFromFormat($formatin, $stamp["timestamp"]);
		$dateout = $adate->format($formatout);
		echo $dateout;
		return $dateout;
}

}//END CLASS

Link to comment
https://forums.phpfreaks.com/topic/286807-timestamp-class-i-wrote/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.