[Python] How to get integer unix timestamps in python? Not casting float to integer

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    the float timestamp used in python seems to be problematic. First it will loose its precision as time come on and second the timestamp is not useable for example like storing in a database big integer field.

    Is there like a predefined way to use integer time. I know the seconds integer can be found using

    timestamp_int = int(datetime.datetime.now().timestamp())


    but wouldn't it have been better if there was a way to do like:

    datetime.datetime.now().itimestamp()


    Is there an official way other than doing a hack around? I mean what is the point of using float when every one else is using integer instead.

    Continue reading...

Compartilhe esta Página