Connecting Tech Pros Worldwide Help | Site Map

Country specific date format

Franz Steinhaeusler
Guest
 
Posts: n/a
#1: Jul 18 '05
Hello,

with following function, i get a human readable date/time format.

mtime = time.strftime(self.timeformat ,time.localtime(st.st_mtime))

However is there a simple solution to get a country specific format:
for example
10/08/2004

and for German:
08.10.2004

I looked in locale class, but I didn't get more wise.

Thank you in advance,

--
Franz Steinhaeusler
Diez B. Roggisch
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Country specific date format


Franz Steinhaeusler wrote:
[color=blue]
> Hello,
>
> with following function, i get a human readable date/time format.
>
> mtime = time.strftime(self.timeformat ,time.localtime(st.st_mtime))
>
> However is there a simple solution to get a country specific format:
> for example
> 10/08/2004
>
> and for German:
> 08.10.2004
>
> I looked in locale class, but I didn't get more wise.[/color]

You didn't look properly:
[color=blue][color=green][color=darkred]
>>> locale.nl_langinfo(locale.D_FMT)[/color][/color][/color]
'%m/%d/%y'[color=blue][color=green][color=darkred]
>>> locale.setlocale(locale.LC_ALL, 'de_DE')
>>> locale.nl_langinfo(locale.D_FMT)[/color][/color][/color]
'%d.%m.%Y'


--
Regards,

Diez B. Roggisch
Franz Steinhäusler
Guest
 
Posts: n/a
#3: Jul 18 '05

re: Country specific date format


On Fri, 08 Oct 2004 13:28:04 +0200, "Diez B. Roggisch"
<deetsNOSPAM@web.de> wrote:
[color=blue]
>Franz Steinhaeusler wrote:
>[color=green]
>> Hello,
>>
>> with following function, i get a human readable date/time format.
>>
>> mtime = time.strftime(self.timeformat ,time.localtime(st.st_mtime))
>>
>> However is there a simple solution to get a country specific format:
>> for example
>> 10/08/2004
>>
>> and for German:
>> 08.10.2004
>>
>> I looked in locale class, but I didn't get more wise.[/color]
>
>You didn't look properly:[/color]

Hi Diez,

you are right :)
[color=blue]
>[color=green][color=darkred]
>>>> locale.nl_langinfo(locale.D_FMT)[/color][/color]
>'%m/%d/%y'[color=green][color=darkred]
>>>> locale.setlocale(locale.LC_ALL, 'de_DE')
>>>> locale.nl_langinfo(locale.D_FMT)[/color][/color]
>'%d.%m.%Y'[/color]

thanks for answering, I have windows XP,
and it seems, this method doesn't exist:

import locale
locale.nl_langinfo(locale.D_FMT)
Traceback (most recent call last):
File "<input>", line 1, in ?
AttributeError: 'module' object has no attribute 'nl_langinfo'
WinXP, Python 2.3.3

from the doc:
nl_langinfo( option)

Return some locale-specific information as a string. This function is
not available on all systems, and the set of possible options might
also vary across platforms. The possible argument values are numbers,
for which symbolic constants are available in the locale module.

is there any possibility ( please WITHOUT the win32 extensions and
other extra package except for wxPython ;) )
to discover the date/time country specific string?

regards

--

Franz Steinhaeusler
DrPython: http://drpython.sourceforge.net/
Project Page: http://sourceforge.net/projects/drpython/
Anna Martelli Ravenscroft
Guest
 
Posts: n/a
#4: Jul 18 '05

re: Country specific date format


Franz Steinhäusler wrote:[color=blue]
> On Fri, 08 Oct 2004 13:28:04 +0200, "Diez B. Roggisch"
> <deetsNOSPAM@web.de> wrote:
>
>[color=green]
>>Franz Steinhaeusler wrote:
>>
>>[color=darkred]
>>>Hello,
>>>
>>>with following function, i get a human readable date/time format.
>>>
>>>mtime = time.strftime(self.timeformat ,time.localtime(st.st_mtime))
>>>
>>>However is there a simple solution to get a country specific format:
>>>for example
>>>10/08/2004
>>>
>>>and for German:
>>>08.10.2004
>>>
>>>I looked in locale class, but I didn't get more wise.[/color]
>>
>>You didn't look properly:[/color]
>
>
> Hi Diez,
>
> you are right :)
>
>[color=green][color=darkred]
>>>>>locale.nl_langinfo(locale.D_FMT)[/color]
>>
>>'%m/%d/%y'
>>[color=darkred]
>>>>>locale.setlocale(locale.LC_ALL, 'de_DE')
>>>>>locale.nl_langinfo(locale.D_FMT)[/color]
>>
>>'%d.%m.%Y'[/color]
>
>
> thanks for answering, I have windows XP,
> and it seems, this method doesn't exist:
>
> import locale
> locale.nl_langinfo(locale.D_FMT)
> Traceback (most recent call last):
> File "<input>", line 1, in ?
> AttributeError: 'module' object has no attribute 'nl_langinfo'
> WinXP, Python 2.3.3
>
> from the doc:
> nl_langinfo( option)
>
> Return some locale-specific information as a string. This function is
> not available on all systems, and the set of possible options might
> also vary across platforms. The possible argument values are numbers,
> for which symbolic constants are available in the locale module.
>
> is there any possibility ( please WITHOUT the win32 extensions and
> other extra package except for wxPython ;) )
> to discover the date/time country specific string?
>
> regards
>[/color]

I would look at dateutil. It has some pretty nifty stuff for handling
timezones and locale-specific date issues...

HTH
Anna
Franz Steinhaeusler
Guest
 
Posts: n/a
#5: Jul 18 '05

re: Country specific date format


On Sun, 10 Oct 2004 21:09:17 GMT, Anna Martelli Ravenscroft
<anna@aleax.it> wrote:
[color=blue]
>[...][color=green]
>> is there any possibility ( please WITHOUT the win32 extensions and
>> other extra package except for wxPython ;) )
>> to discover the date/time country specific string?
>>
>> regards
>>[/color]
>
>I would look at dateutil. It has some pretty nifty stuff for handling
>timezones and locale-specific date issues...
>
>HTH
>Anna[/color]

Hello,

thanks,

did you mean "datetime" instead of "dateutil".
(I couldn't find a dateutil)


--
Franz Steinhaeusler
Alex Martelli
Guest
 
Posts: n/a
#6: Jul 18 '05

re: Country specific date format


Franz Steinhaeusler <franz.steinhaeusler@utanet.at> wrote:
...[color=blue][color=green]
> >I would look at dateutil. It has some pretty nifty stuff for handling
> >timezones and locale-specific date issues...
> >
> >HTH
> >Anna[/color]
>
> Hello,
>
> thanks,
>
> did you mean "datetime" instead of "dateutil".
> (I couldn't find a dateutil)[/color]

(Hmmm, I'd better try to answer for her, she's flying USwards right now
and I'm not sure how good her newsgroup access will be for a while...!)

I think she really meant dateutil -- a wonderful 3rd party extension.
Google for it... it IS worth it (IMHO, and I believe in Anna's too:-).


Alex
Franz Steinhaeusler
Guest
 
Posts: n/a
#7: Jul 18 '05

re: Country specific date format


On Tue, 12 Oct 2004 09:17:12 +0200, aleaxit@yahoo.com (Alex Martelli)
wrote:
[color=blue]
>Franz Steinhaeusler <franz.steinhaeusler@utanet.at> wrote:
> ...[color=green][color=darkred]
>> >I would look at dateutil. It has some pretty nifty stuff for handling
>> >timezones and locale-specific date issues...
>> >
>> >HTH
>> >Anna[/color]
>>
>> Hello,
>>
>> thanks,
>>
>> did you mean "datetime" instead of "dateutil".
>> (I couldn't find a dateutil)[/color]
>
>(Hmmm, I'd better try to answer for her, she's flying USwards right now
>and I'm not sure how good her newsgroup access will be for a while...!)
>
>I think she really meant dateutil -- a wonderful 3rd party extension.
>Google for it... it IS worth it (IMHO, and I believe in Anna's too:-).
>
>
>Alex[/color]

thank you, I found it.

I will give it a try.

--
Franz Steinhaeusler
Closed Thread