Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztimestamp.php
Go to the documentation of this file.
1 <?php
11 class eZTimestamp
12 {
16 public static function getUtcTimestampFromLocalTimestamp( $localTimestamp ) {
17
18 if ( $localTimestamp === null || $localTimestamp === '' )
19 {
20 return null;
21 }
22
23 $utcTimezone = new \DateTimeZone( 'UTC' );
24 $localTimezone = new \DateTimeZone( date_default_timezone_get() );
25
26 $localDate = new \DateTime( null, $localTimezone );
27 $localDate->setTimestamp( $localTimestamp );
28 $utcDate = new \DateTime( $localDate->format( 'Y-m-d H:i:s' ), $utcTimezone );
29
30 return $utcDate->getTimestamp();
31 }
32
36 public static function getLocalTimestampFromUtcTimestamp( $utcTimestamp ) {
37
38 if ( $utcTimestamp === null || $utcTimestamp === '' )
39 {
40 return null;
41 }
42
43 $utcTimezone = new \DateTimeZone( 'UTC' );
44 $localTimezone = new \DateTimeZone( date_default_timezone_get() );
45
46 $utcDate = new \DateTime( null, $utcTimezone );
47 $utcDate->setTimestamp( $utcTimestamp );
48 $localDate = new \DateTime( $utcDate->format( 'Y-m-d H:i:s' ), $localTimezone );
49
50 return $localDate->getTimestamp();
51 }
52 }
53 ?>
eZTimestamp
Definition: eztimestamp.php:12
eZTimestamp\getUtcTimestampFromLocalTimestamp
static getUtcTimestampFromLocalTimestamp( $localTimestamp)
Definition: eztimestamp.php:16
eZTimestamp\getLocalTimestampFromUtcTimestamp
static getLocalTimestampFromUtcTimestamp( $utcTimestamp)
Definition: eztimestamp.php:36
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.