note 103261 added to datetime.settimestamp

From: Date: Mon, 04 Apr 2011 19:40:28 +0000
Subject: note 103261 added to datetime.settimestamp
Groups: php.notes 
Request: Send a blank email to php-notes+get-178492@lists.php.net to get a copy of this message
If your PHP version is lower than 5.3 then you can use this class to be able to use the functions "setTimestamp" and "getTimestamp": <?php class MyDateTime extends DateTime { public function setTimestamp( $timestamp ) { $date = getdate( ( int ) $timestamp ); $this->setDate( $date['year'] , $date['mon'] , $date['mday'] ); $this->setTime( $date['hours'] , $date['minutes'] , $date['seconds'] ); } public function getTimestamp() { return $this->format( 'U' ); } } $date = new MyDateTime(); $date->setTimestamp( $someTimestamp ); echo $date->format( 'd/m/Y H:i:s' ); ?> ---- Server IP: 89.31.146.176 Probable Submitter: 88.169.15.45 ---- Manual Page -- http://www.php.net/manual/en/datetime.settimestamp.php Edit -- https://master.php.net/note/edit/103261 Del: integrated -- https://master.php.net/note/delete/103261/integrated Del: useless -- https://master.php.net/note/delete/103261/useless Del: bad code -- https://master.php.net/note/delete/103261/bad+code Del: spam -- https://master.php.net/note/delete/103261/spam Del: non-english -- https://master.php.net/note/delete/103261/non-english Del: in docs -- https://master.php.net/note/delete/103261/in+docs Del: other reasons-- https://master.php.net/note/delete/103261 Reject -- https://master.php.net/note/reject/103261 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178492) next »