Monday, 26 August 2013

PHP Function date_offset_get()

Syntax

int date_offset_get ( DateTime $object )

int DateTime::getOffset ( void )

Definition and Usage

These functions return the daylight saving time offset.
The above two functions are equivalent and any of the functions can be used as shown below in the example.

Paramters

ParameterDescription
objectRequired. DateTime object

Return Value

Returns DST offset in seconds on success or FALSE on failure.

Example

Following is the usage of this function:
<?php
   $dateSrc = '2007-04-19 12:50 GMT';
   $dateTime = date_create( $dateSrc);;
   $retval = date_offset_get( $dateTime);
   echo "Returned value is $retval";
   echo "<br />";

   # Using second function.
   $dateTime = new DateTime($dateSrc);
   $retval = $dateTime->getOffset();
   echo "Returned value is $retval";
?> 
This will produce following result:
Returned value is -21600
Returned value is -21600

No comments:

Post a Comment