Convert wx.DateTime to python string

546 views
Skip to first unread message

Igor Korot

unread,
Mar 28, 2014, 4:58:25 AM3/28/14
to wxpytho...@googlegroups.com
Hi, ALL,
Is there an easy way to do such a conversion?
Or I have to convert to python datetime object first?

Thank you.
Message has been deleted

Torsten

unread,
Mar 28, 2014, 10:24:31 AM3/28/14
to wxpytho...@googlegroups.com
I think what you are searching for is:
wx.DateTime.Format()
wx.DateTime.FormatDate()
wx.DateTime.FormatTime()

Igor Korot

unread,
Mar 28, 2014, 6:11:49 PM3/28/14
to wxpytho...@googlegroups.com
Hi, Torsten,
I tried to use following code:

date_from = self.date_from.GetValue()
date_to = self.date_to.GetValue()
good_message = "Modification Time between " + date_from.Format('%F',
wx.DateTime.UTC) + " and " + date_to.Format('%F', wx.DateTime.UTC)

But I got python to crash.
It is on Windows XP SP3 32-bit with python 2.7 and wxPython 2.9.4.0.

Any idea?
I'm in US and the self.date_from is the value from the
wx.DatePickerCtrl: 3/28/2014.

Thank you.

>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Igor Korot

unread,
Mar 28, 2014, 8:54:39 PM3/28/14
to wxpytho...@googlegroups.com
ALL,

On Fri, Mar 28, 2014 at 3:11 PM, Igor Korot <ikor...@gmail.com> wrote:
> Hi, Torsten,
>
> On Fri, Mar 28, 2014 at 7:24 AM, Torsten <top...@googlemail.com> wrote:
>> I think what you are searching for is:
>> wx.DateTime.Format()
>> wx.DateTime.FormatDate()
>> wx.DateTime.FormatTime()
>
> I tried to use following code:
>
> date_from = self.date_from.GetValue()
> date_to = self.date_to.GetValue()
> good_message = "Modification Time between " + date_from.Format('%F',
> wx.DateTime.UTC) + " and " + date_to.Format('%F', wx.DateTime.UTC)
>
> But I got python to crash.
> It is on Windows XP SP3 32-bit with python 2.7 and wxPython 2.9.4.0.
>
> Any idea?
> I'm in US and the self.date_from is the value from the
> wx.DatePickerCtrl: 3/28/2014.

On the page: http://www.cplusplus.com/reference/ctime/strftime/ '%F'
is referenced as a valid
format specifier for the strftime() which means, according to wxPython
documentation
it should be possible to use on wx.DateTime Format() function.

Is this a bug in that function?
Or my version of wxPython is not supported this parameter? Because
python is just crashing
without throwing any exceptions.

Thank you.

Torsten

unread,
Mar 29, 2014, 3:32:51 AM3/29/14
to wxpytho...@googlegroups.com
I tried it with %F and it crashes too. I'm on Win7 64Bit, Python 2.7.6 32Bit and wx 2.9.5.

%F is equivalent to %Y-%m-%d  and that is working. Maybe there's really a bug.

Igor Korot

unread,
Mar 29, 2014, 3:44:13 AM3/29/14
to wxpytho...@googlegroups.com
Torsten,
Thank you for confirming.
Hopefully Robin will be able to check whether it is really a bug or not.

Unfortunately I don't have wxWidgets compiled on this machine to
check. I installed wxPython from the binary package....

Steve Barnes

unread,
Mar 29, 2014, 4:11:25 AM3/29/14
to wxpytho...@googlegroups.com
Easy:
python -c"import wx;now=wx.DateTime.Now();s_now=str(now);print s_now;"
Sat Mar 29 08:10:23 2014



Robin Dunn

unread,
Apr 10, 2014, 8:38:08 PM4/10/14
to wxpytho...@googlegroups.com
Igor Korot wrote:
> Torsten,
>
> On Sat, Mar 29, 2014 at 12:32 AM, Torsten<top...@googlemail.com> wrote:
>> I tried it with %F and it crashes too. I'm on Win7 64Bit, Python 2.7.6 32Bit
>> and wx 2.9.5.
>>
>> %F is equivalent to %Y-%m-%d and that is working. Maybe there's really a
>> bug.
>
> Thank you for confirming.
> Hopefully Robin will be able to check whether it is really a bug or not.

Yes it appears to be a bug with %F, and only on Windows. Please search
for a Trac ticket about it and add one if you don't find one already there.


--
Robin Dunn
Software Craftsman
http://wxPython.org
Reply all
Reply to author
Forward
0 new messages