|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-10 18:23 UTC] vadimx at gmail dot com
Description:
------------
When i use unixtime in DateTime object, this returning wrong date, -1 day.
Test script:
---------------
$date = '7.8.2010';
echo "String: ".$date."<br>";
$date_format = 'j.m.Y';
$unixtime = strtotime($date);
echo "Unixtime: ".$unixtime."<br>";
echo "Date(PHP): ".date($date_format,$unixtime)."<br>";
$date = new DateTime('@'.$unixtime);
echo "DateTime(PHP Class): ".$date->format($date_format);
Expected result:
----------------
String: 7.8.2010
Unixtime: 1281128400
Date(PHP): 7.08.2010
DateTime(PHP Class): 7.08.2010
Actual result:
--------------
String: 7.8.2010
Unixtime: 1281128400
Date(PHP): 7.08.2010
DateTime(PHP Class): 6.08.2010
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 16:00:02 2025 UTC |
date_default_timezone_set('Europe/Kiev'); But, i try change timezone, but this no effect.For example, using date_default_timezone_set('UTC'); I cannot reproduce it. But using your timezone I got same result.When i use date_default_timezone_set('UTC'), all ok. But in doc "Note: The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010- 01-28T15:00:00+02:00).". why timezone affect to unixtime?