DateTime according to wx.Locale

My idea was to display the date according to locale.
If locale is set to English the date will be format mm / dd / yy, if locale is set to Italian the date will be format dd / mm / yy and so on.

The code would be something like this:

b = wx,Locale(wx.LANGUAGE_ENGLISH)

#wx.Locale(wx.LANGUAGE_ITALIAN)

a = wx.DateTime.Today()

if b.GetLocale() = ‘italian’:

a.Format(’%d-%m-%Y’)

if b.GetLocale() = ‘english’;

a.Format(’%m-%d-%Y’)

There is no way to make this more automatic without controls?

···


Fabio Spadaro
www.fabiospadaro.com

Fabio Spadaro wrote:

My idea was to display the date according to locale.
If locale is set to English the date will be format mm / dd / yy, if
locale is set to Italian the date will be format dd / mm / yy and so on.
The code would be something like this:

b = wx,Locale(wx.LANGUAGE_ENGLISH)
#wx.Locale(wx.LANGUAGE_ITALIAN)
...
...

a = wx.DateTime.Today()
if b.GetLocale() = 'italian':
          a.Format('%d-%m-%Y')
if b.GetLocale() = 'english';
          a.Format('%m-%d-%Y')

There is no way to make this more automatic without controls?
--
Fabio Spadaro
www.fabiospadaro.com <http://www.fabiospadaro.com>
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Is that actually from your code? I believe you meant ==, not = (syntax
errror).
Also, the locale is returned capitalised. Check for "Italian", not
"italian".

Anyway, use these methods:

ParseDateTime(self, datetime)
Identical to calling Format() with "%x" argument (which means 'preferred
date representation for the current locale').

ParseFormat(self, date, format, dateDef)
Identical to calling Format() with "%X" argument (which means 'preferred
time representation for the current locale')

···

--
Steven Sproat, BSc

Try wx.LANGUAGE_ENGLISH_US, some locales where English is spoken the day-first date is the accepted standard, so you need to get more specific. Also, there is the FormatDate method that does the same as Format('%x') but might be a little easier to remember.

···

On 7/21/10 3:10 AM, Fabio Spadaro wrote:

Anyway I tried
         a = wx.Locale(wx.LANGUAGE_ENGLISH)
         b = wx.DateTime.Today()
         print b.Format("%x")
but the date is displayed in the format Italian(u'21/07/2010')

--
Robin Dunn
Software Craftsman

Hi Robin,

···

2010/7/21 Robin Dunn robin@alldunn.com

On 7/21/10 3:10 AM, Fabio Spadaro wrote:

Anyway I tried

     a = wx.Locale(wx.LANGUAGE_ENGLISH)

     b = wx.DateTime.Today()

     print b.Format("%x")

but the date is displayed in the format Italian(u’21/07/2010’)

Try wx.LANGUAGE_ENGLISH_US, some locales where English is spoken the day-first date is the accepted standard, so you need to get more specific. Also, there is the FormatDate method that does the same as Format(‘%x’) but might be a little easier to remember.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Thanks, the
wx.LANGUAGE_ENGLISH option does work.


Fabio Spadaro
www.fabiospadaro.com