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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.