[Python] How to convert datetime object to milliseconds

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am parsing datetime values as follows:

    df['actualDateTime'] = pd.to_datetime(df['actualDateTime'])


    How can I convert this datetime objects to milliseconds?

    I didn't see mention of milliseconds in the doc of to_datetime.

    Update (Based on feedback): This is the current version of the code that provides error TypeError: Cannot convert input to Timestamp. The column Date3 must contain milliseconds (as a numeric equivalent of a datetime object).

    import pandas as pd
    import time

    s1 = {'Date' : ['2015-10-20T07:21:00.000','2015-10-19T07:18:00.000','2015-10-19T07:15:00.000']}

    df = pd.DataFrame(s1)

    df['Date2'] = pd.to_datetime(df['Date'])

    t = pd.Timestamp(df['Date2'])

    df['Date3'] = time.mktime(t.timetuple())

    print df

    Continue reading...

Compartilhe esta Página