php, normal date is correct, but gmdate is not accurate

John Smith

I have to do calculates with GMT date, but it looks like there is a bug, or I dont understand something.

echo date('Y-m-d H:i:s').'<br>';
$time = strtotime(date('Y-m-d H:i:s'));
// calculations will come
$time = date('Y-m-d H:i:s', $time);
echo $time.'<br>';

this prints the same dates, as it was expected. But this:

echo gmdate('Y-m-d H:i:s').'<br>';
$time = strtotime(gmdate('Y-m-d H:i:s'));
// calculations will come
$time = gmdate('Y-m-d H:i:s', $time);
echo $time.'<br>';

is not the same. What am I doing wrong? I have to use GMT time, its an international site.

Oswald

strtotime uses the local time zone, unless the passed string has timezone information. Dates of the format 'Y-m-d H:i:s' do not contain time zone information.

In strtotime(gmdate('Y-m-d H:i:s')), the function strtotime assumes that the passed string specifies a date in the local timezone, but it actually is in GMT.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

php, normal date is correct, but gmdate is not accurate

From Dev

Using strtotime() PHP and revert back trough gmdate() is not returning same date

From Dev

Different results for date() and gmdate()

From Dev

PHP - gmdate() and Large Integers

From Dev

date() and gmdate() return different results

From Dev

php gmdate() Incorrect time zone

From Dev

PHP date() not correct

From Dev

PHP Not calculating correct date

From Dev

Store a value in MySQL made from gmdate() in PHP

From Dev

PHP: Get age accurate to month but not day (from a date)

From Dev

PHP date() not returning correct time?

From Dev

Getting PHP Date format correct

From Dev

How to convert regional date into normal format date in PHP?

From Dev

when i add 2 hours in gmdate it will zero minutes in Php

From Dev

3rd Last Day of the Month using PHP gmdate()

From Dev

Not getting correct current time in PHP using date()

From Dev

Date is not accurate while saving parseObject

From Dev

Finding the correct orientation for the normal

From Dev

PHP: rowCount() now accurate counting?

From Dev

How to convert the MongoDB ISO date to Normal date-Mongodb with PHP , and MongoDb driver

From Dev

pandas.date_range accurate freq parameter

From Dev

Converting milliseconds date to normal date

From Dev

Delphi Julian Date to Normal Date

From Dev

The correct way to calculate normal matrix?

From Dev

The correct way to calculate normal matrix?

From Dev

PHP date showing wrong time despite the timestamp being correct

From Dev

date_create_from_format php on certain month and date does not return correct date

From Dev

the most accurate way to calucate date periods using the date object

From Dev

Google Maps reverse geocode doesn't return correct/accurate address

Related Related

  1. 1

    php, normal date is correct, but gmdate is not accurate

  2. 2

    Using strtotime() PHP and revert back trough gmdate() is not returning same date

  3. 3

    Different results for date() and gmdate()

  4. 4

    PHP - gmdate() and Large Integers

  5. 5

    date() and gmdate() return different results

  6. 6

    php gmdate() Incorrect time zone

  7. 7

    PHP date() not correct

  8. 8

    PHP Not calculating correct date

  9. 9

    Store a value in MySQL made from gmdate() in PHP

  10. 10

    PHP: Get age accurate to month but not day (from a date)

  11. 11

    PHP date() not returning correct time?

  12. 12

    Getting PHP Date format correct

  13. 13

    How to convert regional date into normal format date in PHP?

  14. 14

    when i add 2 hours in gmdate it will zero minutes in Php

  15. 15

    3rd Last Day of the Month using PHP gmdate()

  16. 16

    Not getting correct current time in PHP using date()

  17. 17

    Date is not accurate while saving parseObject

  18. 18

    Finding the correct orientation for the normal

  19. 19

    PHP: rowCount() now accurate counting?

  20. 20

    How to convert the MongoDB ISO date to Normal date-Mongodb with PHP , and MongoDb driver

  21. 21

    pandas.date_range accurate freq parameter

  22. 22

    Converting milliseconds date to normal date

  23. 23

    Delphi Julian Date to Normal Date

  24. 24

    The correct way to calculate normal matrix?

  25. 25

    The correct way to calculate normal matrix?

  26. 26

    PHP date showing wrong time despite the timestamp being correct

  27. 27

    date_create_from_format php on certain month and date does not return correct date

  28. 28

    the most accurate way to calucate date periods using the date object

  29. 29

    Google Maps reverse geocode doesn't return correct/accurate address

HotTag

Archive