[Python] Python fromtimestamp OSError

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    For some reason when constructing datetimes using fromtimestamp, I get a


    "OSError [Errno22] Invalid Argument"
    ​

    when I use negative times less than -43200 (-12hrs). I am on Win7 64-bit and python 3.5.1. Here's code that produces the error.

    >>> import datetime
    >>> import pytz
    >>> datetime.datetime.fromtimestamp(-43200, pytz.utc)
    datetime.datetime(1969, 12, 31, 12, 0, tzinfo=<UTC>)
    >>> datetime.datetime.fromtimestamp(-43201, pytz.utc)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    OSError: [Errno 22] Invalid argument


    The sample uses pytz to simplify timezone information, but the error also occurs without it.

    Continue reading...

Compartilhe esta Página