Home > Software design >  How to convert date time to timestampe in python?
How to convert date time to timestampe in python?

Time:12-31

I have a dataset that has a column of that date written in the following format. How can I convert them to timestamp?

date = 1/1/2016  1:00:00 AM

CodePudding user response:

you may need to use datetime library:

import datetime
datestr = "1/1/2016   1:00:00 AM"

datetm =datetime.datetime.strptime(
    datestr, '%d/%m/%Y %H:%M:%S %p')

datetime.datetime.timestamp(datetm)

output:

1451610000.0

More info on formats, etc.: docs

  • Related