473,769 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.co m>
Jun 19 '07 #1
3 2478
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.or g.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.co m>
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.pope n(cmd, 'r', 1)
output = "".join(handler .readlines()).s trip()
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.strf time("%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
2686
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
5980
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 character argument. I am assuming that the compiler does some type casting or that char's are
0
2264
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/ default-character-set=cp1251 Then restarted server and created a simple database
1
2385
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 code page / character set conversion take place? I am particulary interested in insert/update from subqueries. eg: insert into t1(binarycol) select :HV1 from t2 versus
22
11956
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 every character starts with ^@. I've seen e.g. http://aktuell.de.selfhtml.org/artikel/javascript/utf8b64/utf8.htm#a5 as
6
2236
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); string s = t.ToString(); The trouble now is that the s object now contains the ASCII character (63) now. I know because when I store the string to SQL database it show the
5
2283
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 character conversion. I also tried using UTF7-8 and Unicode conversions, but the output is still converted. How do i get past this? Thanks in advance, Kasper Hansen
3
12015
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 as ODBC, then i am getting
1
11279
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 and disable "Automatic ANSI to OEM conversion": - This only affects isql from the command line, and no gui applications - http://support.microsoft.com/?scid=kb;EN-US;153449 - Start the "Client Network Utility" C:\WINDOWS\system32\cliconfg.exe
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.