Search code examples
python-3.xwxpythonwxwidgets

WxForms DateTime to Python DateTime


I need to convert DateTime from WxWidget

Fri Sep 28 00:00:00 2018

To another format like :

28/09/18 20:35:00

But i can't find anything to do


Solution

  • Use wx.DateTime Format()
    i.e.

    d=wx.DateTime.Now()
    d
    <wx.DateTime: "Sat Sep 29 10:35:28 2018">
    d.Format('%d/%m/%y %H:%M:%S')
    '29/09/18 10:35:28'
    

    For the format options see datetime manual pages https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior

    For wx.DateTime options, see https://wxpython.org/Phoenix/docs/html/wx.DateTime.html

    To generate an actual python datetime (as per your question heading):

    f = d.Format('%d/%m/%y %H:%M:%S')
    x = datetime.datetime.strptime(f,'%d/%m/%y %H:%M:%S')
    x
    datetime.datetime(2018, 9, 29, 10, 35, 28)