Search code examples
pythonutc

How to convert 01/01/2012 01:00:00 to utc?


I have tried to convert my time data so that that my python script can read this data. I have tried

Time.append(row[1])
Time = Time[1:]
    Time = [str (i) for i in Time]

datetime_Time = datetime.datetime ("%Y%m%d %I:%M:%S") #pharsing the time
    print (Time)

I have tried passing the data as a float and as an integer too.But as my data uses "/" and :, this therefore is causing an error and would appreciate if anyone could show me how to read this data


Solution

  • This should help.

    import datetime
    s = "01/01/2012 01:00:00"
    print( datetime.datetime.strptime(s, "%m/%d/%Y %H:%M:%S").strftime("%Y%m%d %I:%M:%S") )
    

    Output:

    20120101 01:00:00