diff options
Diffstat (limited to 'php/src/Google/Protobuf/Timestamp.php')
-rw-r--r-- | php/src/Google/Protobuf/Timestamp.php | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/php/src/Google/Protobuf/Timestamp.php b/php/src/Google/Protobuf/Timestamp.php index a793c7e3..6d26f6c5 100644 --- a/php/src/Google/Protobuf/Timestamp.php +++ b/php/src/Google/Protobuf/Timestamp.php @@ -182,18 +182,19 @@ class Timestamp extends \Google\Protobuf\Internal\Message */ public function fromDateTime(\DateTime $datetime) { - $this->seconds = $datetime->format('U'); - $this->nanos = 0; + $this->seconds = $datetime->getTimestamp(); + $this->nanos = 1000 * $datetime->format('u'); } /** - * Converts Timestamp to PHP DateTime. Nano second is ignored. + * Converts Timestamp to PHP DateTime. * * @return \DateTime $datetime */ public function toDateTime() { - return \DateTime::createFromFormat('U', $this->seconds); + $time = sprintf('%s.%06d', $this->seconds, $this->nanos / 1000); + return \DateTime::createFromFormat('U.u', $time); } } |