• Álvaro González (github)

    Notably, PHP pins the Unix timestamp to UTC+00:00, aka GMT.

    PHP's Unix time is the number of seconds since Unix Epoch, like everybody else.

  • LZ79LRU (unregistered) in reply to Álvaro González

    Yes. But given that this is PHP we are talking about readers would be excused for being surprised about that fact.

  • (nodebb)

    This function has the effect of flooring to second. It's a terrible way to do that, but it's not a no-op.

  • (nodebb)

    So this function takes a time, formats it, parses the format to get what should be the same time back.

    Except when it shouldn't.

    $ cat time.php
    <?php
        $utc_str = gmdate("M d Y H:i:s", time());
        echo strtotime($utc_str) . PHP_EOL;
        date_default_timezone_set('America/New_York'); // or set date.timezone in .htaccess or php.ini
        echo strtotime($utc_str) . PHP_EOL;
    
    $ php -f time.php
    1729079464
    1729093864
    $ 
    

    Of course, changing the default timezone can be a WTF in and of itself...

  • LZ79LRU (unregistered)

    PHP and WTF have the same character count. Coincidence? Or is it maybe inspiration? Could our ancestors have been inspired to create PHP by access to extraterrestrial knowledge? Could its many insane and idiotic idiosyncrasies be nothing but errors in translation resulting from our inability to understand advanced alien programming paradigms?

    See this and more as we reveal the ultimate truth in the next episode of Ancient Programmers.

  • dusoft (unregistered) in reply to LZ79LRU

    LZ79LRU and TROLL do not have he same character count, but they come close.

  • (nodebb) in reply to Mr. TA

    time() returns the time as an integer number of seconds, so it's already floored.

  • TheCPUWizard (unregistered)

    Each parameter of strtime function uses the default time zone unless a time zone is specified in that parameter. Be careful not to use different time zones in each parameter unless that is intended. See date_default_timezone_get() on the various ways to define the default time zone. https://www.php.net/manual/en/function.strtotime.php

  • (nodebb) in reply to Barry Margolin

    Interesting, I thought it's usually in milliseconds. Oh well, still a giant WTF.

  • Darren (unregistered)

    It's using GMT as the timezone, but the date is in the American month-day-year format. That seems odd.

  • löchlein deluxe (unregistered)

    I'd like to take the opportunity to share my favourite atd "feature":

    $ echo '/bin/true' | at now
    job 4 at Thu Oct 17 07:00:00 2024
    $ echo '/bin/true' | at 'Thu Oct 17 07:00:00 2024'
    syntax error. Last token seen: Oct
    Garbled time
    

    Yes, it understands almost any time spec, including "at teatime", but not the one format it emits.

  • (nodebb)

    What this function is returns a new timestamp that forces the epoch to be 1970-01-01 00:00:00 in the current timezone (whatever that has been configured to be). So if your timezone is at UTC-8 then yourTime() (no way is it myTime()) would return a timestamp that is 28800 less than the Unix timestamp.

    In other words: it takes the Unix timestamp, subtracts the current timezone's offset from UTC, and returns the result.

    function myTime() {
        return time() + date('Z');
    }
    

    Addendum 2024-10-17 02:41: Adds, subtracts: depends on which side you're looking at it from.

  • selfdefenseclasses (unregistered)

    "Thank you for sharing this update on the revamped SafetyWing Nomad Insurance claim process! I really appreciate the focus on making it easier and more efficient for travelers. Having reliable and hassle-free insurance is so important for digital nomads, and this is a great step forward. Your post is super helpful!"

    "Thank you for sharing this update on the revamped SafetyWing Nomad Insurance claim process! I really appreciate the focus on making it easier and more efficient for travelers. Having reliable and hassle-free insurance is so important for digital nomads, and this is a great step forward. Your post is super helpful!"

  • Industrial Automation Engineer (unregistered)

    TRWTF is not naming it gmtdate

  • Drak (unregistered)

    The documentation of strtotime leaves me baffled: The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in baseTimestamp, or the current time if baseTimestamp is not supplied.

    What is 'the number of seconds since 1 jan 1970 relative to <another time>' meant to mean?

  • LZ79LRU (unregistered) in reply to Drak

    If it's anything like the C# DateTimeOffset which is described similarly it's basically an offset. So say you have a unix timestamp of 3600 and a date time of now. That would mean now + 1 minute. That sort of thing is really useful when communicating with asinine systems that insist on having their interfaces output all time values in "unix" seconds.

  • (nodebb) in reply to Drak

    Indeed, the UNIX epoch time should always be in UTC, as it is the base from which all timezones are calculated from.

    If the epoch were to be offset and then fed to any standard tool or function that takes an UNIX epoch value, you would get unexpected results since the expectation is that the value is the "number of seconds since January 1 1970 00:00:00 UTC", emphasis on UTC.

Leave a comment on “Time to Change”

Log In or post as a guest

Replying to comment #:

« Return to Article