php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52870 DateTime ignoring timezone when outputting unix timestamp
Submitted: 2010-09-17 15:03 UTC Modified: 2010-09-17 15:24 UTC
From: great at km13 dot ru Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.3 OS: all
Private report: No CVE-ID: None
 [2010-09-17 15:03 UTC] great at km13 dot ru
Description:
------------
If I create a new DateTime object with different timezone and then try to get Unixtimestamp ('U'), I always get timestamp of my current timezone.

Test script:
---------------
// UTC+5
$date = new DateTime( 'now', new DateTimezone( 'Asia/Yekaterinburg' ) );
echo $date->format( 'U' ) . "\n";

// UTC+3
$date = new DateTime( 'now', new DateTimezone( 'Europe/Moscow' ) );
echo $date->format( 'U' );


Expected result:
----------------
1284734980
1284727780

Actual result:
--------------
1284727780
1284727780

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-17 15:24 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2010-09-17 15:24 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Unix timestamps are a moment in time and so timezones have no influences on them. They count the number of seconds since 1970-01-01 00:00 *UTC*
See: http://en.wikipedia.org/wiki/Unix_time
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 06:01:28 2024 UTC