473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

stftime %z time conversion character

Although it is not present in ANSI C, the GNU version of stftime
supports the conversion character %z, which is a time offset from GMT.
The four digit time offset is required in RFC 2822 dates/times, and is
used by a number of other programs as well. I need to convert times
that use this convention to python time representations, and because
Python does not support the %z time conversion character I cannot
simply use the time.strptime function.

What solutions have people used for this? I'm currently thinking of
creating a dict that maps four digit time offsets to the time zone
name and then use the %Z token on that. Is there another (or better)
way?

--
Evan Klitzke <ev**@yelp.com>
Jun 19 '07 #1
3 2440
Evan Klitzke wrote:
Although it is not present in ANSI C, the GNU version of stftime
supports the conversion character %z, which is a time offset from GMT.
The four digit time offset is required in RFC 2822 dates/times, and is
used by a number of other programs as well. I need to convert times
that use this convention to python time representations, and because
Python does not support the %z time conversion character I cannot
simply use the time.strptime function.
See this patch for an idea of the scope of this problem:

https://sourceforge.net/tracker/?fun...&group_id=5470
What solutions have people used for this? I'm currently thinking of
creating a dict that maps four digit time offsets to the time zone
name and then use the %Z token on that. Is there another (or better)
way?
Apart from a patch which would allow the time module functions to
produce the output you desire, an alternative might involve the
datetime module and timezone-aware datetime objects:

http://groups.google.com/group/comp....48f3054b4f3eae

I refer indirectly to the pytz module in the above message:

http://pytz.sourceforge.net/

Paul

Jun 19 '07 #2
On 6/19/07, Paul Boddie <pa**@boddie.org.ukwrote:
Evan Klitzke wrote:
Although it is not present in ANSI C, the GNU version of stftime
supports the conversion character %z, which is a time offset from GMT.
The four digit time offset is required in RFC 2822 dates/times, and is
used by a number of other programs as well. I need to convert times
that use this convention to python time representations, and because
Python does not support the %z time conversion character I cannot
simply use the time.strptime function.

See this patch for an idea of the scope of this problem:

https://sourceforge.net/tracker/?fun...&group_id=5470
What solutions have people used for this? I'm currently thinking of
creating a dict that maps four digit time offsets to the time zone
name and then use the %Z token on that. Is there another (or better)
way?

Apart from a patch which would allow the time module functions to
produce the output you desire, an alternative might involve the
datetime module and timezone-aware datetime objects:

http://groups.google.com/group/comp....48f3054b4f3eae

I refer indirectly to the pytz module in the above message:

http://pytz.sourceforge.net/

Paul
Thanks Paul, your answer was very helpful.

--
Evan Klitzke <ev**@yelp.com>
Jun 20 '07 #3
Evan Klitzke wrote:
Although it is not present in ANSI C, the GNU version of stftime
supports the conversion character %z, which is a time offset from GMT.
The four digit time offset is required in RFC 2822 dates/times, and is
used by a number of other programs as well. I need to convert times
that use this convention to python time representations, and because
Python does not support the %z time conversion character I cannot
simply use the time.strptime function.

What solutions have people used for this? I'm currently thinking of
creating a dict that maps four digit time offsets to the time zone
name and then use the %Z token on that. Is there another (or better)
way?
I had a similar problem, currently I had solved with a system call

#The Linux Date Command: TZ=WET date -d "20070823" +%:z
#example
timezone = "WET"
year = 2007
month = 2
day = 27
#end of example
cmd="TZ=%s /bin/date -d %.4d%.2d%.2d +%%z" % (timezone,year,month,day)
print "DEBUG cmd=%s" % cmd
handler=os.popen(cmd, 'r', 1)
output = "".join(handler.readlines()).strip()
tz=output[:3]+":"+output[3:]
handler.close()
print "DEBUG timezone=%sXX" % tz

----------------------------
before I test timezone of my machines like this :
import time
tzstr=time.strftime("%Z",time.localtime())
if tzstr == "WEST" :
do something

Hope that can help something

Best regards,
--
Sérgio M. B.
Jun 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kamal | last post by:
PHP 4.3.4 on Apache 2.0.48 on Linux Red Hat 8.0 Kernel 2.4.18-14smp with Oracle 9iR2. I have this code: <html> <body> <?php
8
by: Michael Gaab | last post by:
How would I force the compiler to throw an error for the following: function signature - void foo(short); function call - foo('d'); My compiler does not complain when I call foo() with a...
0
by: Tumurbaatar S. | last post by:
Hi, I'm running MySQL 3.23.55 on WinXP and have some problem using non latin charset. I've added these 2 lines under group of my.ini: character-sets-dir = c:/mysql/share/charsets/...
1
by: Aakash Bordia | last post by:
Hello, Does anybody know what is the documented and known behavior of inserting/updating binary columns using host variables from a client to a server which have different code pages? Will any...
22
by: Martin Trautmann | last post by:
Hi all, is there any kind of 'hiconv' or other (unix-like) conversion tool that would convert UTF-8 to HTML (ISO-Latin-1 and Unicode)? The database output is UTF-8 or UTF-16 only - Thus almost...
6
by: KA Kueh | last post by:
Dear all, I have a requirement to replace the ' character with ASCII character (146) in C# but it seems that when I do the following the conversion is lost. char t = Convert.ToChar(146);...
5
by: Kasper Hansen | last post by:
I need to search through a binary file to find a specific string and then replace it with another string. However the System.Text.Encoding.ASCII.GetString method i originally used seems to do some...
3
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type...
1
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.