Automatically get the time taking day light saving hours into account

webnoob

I think I'm going nuts as this has to be simple.

The time on my computer is currently: 14:41 When I run any of the code below, it returns: 13:41.

$date = new DateTime();
$date->format('Y-m-d H:i:s') //13:41
date('Y-m-d H:i:s') //13:41

date_default_timezone_get() returns UTC.

Now I understand why it's an hour behind (because we are in daylight saving time) BUT isn't there a function that takes all this into account and returns the actual time?

p.s I am expecting to have missed something obvious here.

Edit: date('Y-m-d H:i:s -- I -- e'); returns 2013-09-13 14:15:47 -- 0 -- UTC. Shouldn't the I param be return 1?

Peter

Don't rely on php.ini settings. If you want control over the timezone, control the timezone:

<?php

$date = new DateTime();
$date->setTimezone(new DateTimeZone('Europe/London'));
$date->format('Y-m-d H:i:s e')

Replace "Europe/London" with whatever your definition of "actual time" is.

As an aside: if date_default_timezone_get() returns UTC, then the output of $date->format() is the same on every machine with a correct clock. That's the point of UTC.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Not taking into account condition

분류에서Dev

MySQL get next day & time combination

분류에서Dev

How to center without taking into account a floated element?

분류에서Dev

How to get results comparing only the day and month, ignoring the time of a timestamp?

분류에서Dev

Remove hours from time series

분류에서Dev

mysql: automatically convert seconds to hours for some columns

분류에서Dev

JavaScript formatting time 24hours format to 12hours

분류에서Dev

awk: change whitespaces with tabs taking titles and empty fields into account

분류에서Dev

Taking time to load the image from URL to UIImageview

분류에서Dev

Ubuntu taking way too long time to start

분류에서Dev

Graphx EdgeRDD count taking long time to compute

분류에서Dev

Why is MATLAB job taking a long time running?

분류에서Dev

How to output time remaining in days or hours with liquid?

분류에서Dev

Time count and session variable for 4 hours long time

분류에서Dev

Automatically set an updatedAt time on a record

분류에서Dev

Testing for daylight saving time within Cocoa and CocoaTouch

분류에서Dev

Get a web page every 5 hours

분류에서Dev

get start of the day in sql

분류에서Dev

Automatically saving a big document that is fragmented over many webpages

분류에서Dev

Converting 24hours time format to 12hours for slider bar

분류에서Dev

Basic Javascript Countdown Timer Taking Longer Than Time Set

분류에서Dev

php turning number (hours) to php date and time format

분류에서Dev

Only display hours if time is greater than 60 minutes

분류에서Dev

How to get Daylight Saving into a Date Arithmetic Formula?

분류에서Dev

start openvpn client automatically at certain time?

분류에서Dev

automatically quit less after a short time

분류에서Dev

How to change layout of an activity automatically on day change ? any simple way?

분류에서Dev

Matching value on date (year, month, day) but not time

분류에서Dev

how to Store the Calender Remainder on Day with time in android

Related 관련 기사

  1. 1

    Not taking into account condition

  2. 2

    MySQL get next day & time combination

  3. 3

    How to center without taking into account a floated element?

  4. 4

    How to get results comparing only the day and month, ignoring the time of a timestamp?

  5. 5

    Remove hours from time series

  6. 6

    mysql: automatically convert seconds to hours for some columns

  7. 7

    JavaScript formatting time 24hours format to 12hours

  8. 8

    awk: change whitespaces with tabs taking titles and empty fields into account

  9. 9

    Taking time to load the image from URL to UIImageview

  10. 10

    Ubuntu taking way too long time to start

  11. 11

    Graphx EdgeRDD count taking long time to compute

  12. 12

    Why is MATLAB job taking a long time running?

  13. 13

    How to output time remaining in days or hours with liquid?

  14. 14

    Time count and session variable for 4 hours long time

  15. 15

    Automatically set an updatedAt time on a record

  16. 16

    Testing for daylight saving time within Cocoa and CocoaTouch

  17. 17

    Get a web page every 5 hours

  18. 18

    get start of the day in sql

  19. 19

    Automatically saving a big document that is fragmented over many webpages

  20. 20

    Converting 24hours time format to 12hours for slider bar

  21. 21

    Basic Javascript Countdown Timer Taking Longer Than Time Set

  22. 22

    php turning number (hours) to php date and time format

  23. 23

    Only display hours if time is greater than 60 minutes

  24. 24

    How to get Daylight Saving into a Date Arithmetic Formula?

  25. 25

    start openvpn client automatically at certain time?

  26. 26

    automatically quit less after a short time

  27. 27

    How to change layout of an activity automatically on day change ? any simple way?

  28. 28

    Matching value on date (year, month, day) but not time

  29. 29

    how to Store the Calender Remainder on Day with time in android

뜨겁다태그

보관