473,795 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

different time tuple format

hi all, sorry if i'm reposting

why time.strptime and time.localtime returns tuple with different DST (9 item of the tuple)?
is there some of setting to fix the problem?
Python 2.2.3 (#1, May 31 2005, 11:33:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright" , "credits" or "license" for more information.
import time
time.strptime(" 2005-06-07 21:00:00", "%Y-%m-%d %H:%M:%S") (2005, 6, 7, 21, 0, 0, 6, 1, 0) time.localtime( ) (2005, 6, 7, 21, 2, 39, 1, 158, 1)

--
Best regards,
Maksim Kasimov
mailto: ka*****@i.com.u a
Jul 19 '05 #1
10 2328
http://docs.python.org/lib/module-time.html tells us the last element
is the DST flag, on your computer that applies for localtime(). To get
this with strptime() you have to tweak the %Z formatter - this is
platform specific.

Jul 19 '05 #2
Like the last poster said, use %Z. On my Mandriva Linux system I get the
following results:
time.localtime( ) (2005, 6, 7, 15, 7, 12, 1, 158, 1) time.strptime(" 2005-06-07 15:07:12 EDT", "%Y-%m-%d %H:%M:%S %Z")
(2005, 6, 7, 15, 7, 12, 1, 158, 1)

Rick

Maksim Kasimov wrote:
hi all, sorry if i'm reposting

why time.strptime and time.localtime returns tuple with different DST (9
item of the tuple)? is there some of setting to fix the problem?
Python 2.2.3 (#1, May 31 2005, 11:33:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright" , "credits" or "license" for more information. >>> import time
>>> time.strptime(" 2005-06-07 21:00:00", "%Y-%m-%d %H:%M:%S") (2005, 6, 7, 21, 0, 0, 6, 1, 0) >>> time.localtime( ) (2005, 6, 7, 21, 2, 39, 1, 158, 1) >>>



Jul 19 '05 #3
Rick Holbert wrote:
Like the last poster said, use %Z. On my Mandriva Linux system I get the
following results:

time.localt ime()
(2005, 6, 7, 15, 7, 12, 1, 158, 1)
time.strpti me("2005-06-07 15:07:12 EDT", "%Y-%m-%d %H:%M:%S %Z") (2005, 6, 7, 15, 7, 12, 1, 158, 1)


does not work at all: "ValueError : format mismatch"

i've check the value of time.tzname:
('EET', 'EEST')

and get the following (again):
time.strptime(" 2005-06-07 15:07:12 EET", "%Y-%m-%d %H:%M:%S %Z")

(2005, 6, 7, 15, 7, 12, 6, 1, 0)



--
Best regards,
Maksim Kasimov
mailto: ka*****@i.com.u a
Jul 19 '05 #4
In your case it is the EEST, as this is the DST timezone (see again:
http://docs.python.org/lib/module-time.html)

** martin@ubuntu:~ $ python
** Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
** [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
** Type "help", "copyright" , "credits" or "license" for more
information.
** >>> import time
** >>> print time.tzname
** ('CET', 'CEST')
** >>> time.strptime(" 2005-06-07 15:07:12 CET", "%Y-%m-%d %H:%M:%S %Z")
** (2005, 6, 7, 15, 7, 12, 1, 158, 0)
** >>> time.strptime(" 2005-06-07 15:07:12 CEST", "%Y-%m-%d %H:%M:%S
%Z")
** (2005, 6, 7, 15, 7, 12, 1, 158, 1)
** >>>

Jul 19 '05 #5

seems like it is not a platform specific,
i think to solve the problem i need put settings in order (in php it is php.ini file) thus i'll have a portable code.
i've check the following code on my various servers, and it gives me different results:

import time
time.tzname
time.daylight
time.strptime(" 2005-06-07 15:07:12", "%Y-%m-%d %H:%M:%S")
time.strptime(" 2005-06-07 15:07:12 EEST", "%Y-%m-%d %H:%M:%S %Z")


Python 2.3.3 (#1, Feb 28 2004, 20:35:22)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright" , "credits" or "license" for more information.
import time
time.tzname ('EET', 'EEST') time.daylight 1 time.strptime(" 2005-06-07 15:07:12", "%Y-%m-%d %H:%M:%S") (2005, 6, 7, 15, 7, 12, 1, 158, -1) time.strptime(" 2005-06-07 15:07:12 EEST", "%Y-%m-%d %H:%M:%S %Z") (2005, 6, 7, 15, 7, 12, 1, 158, 1)

Python 2.2.3 (#1, Oct 22 2004, 03:10:44)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright" , "credits" or "license" for more information. import time
time.tzname ('EET', 'EEST') time.daylight 1 time.strptime(" 2005-06-07 15:07:12", "%Y-%m-%d %H:%M:%S") (2005, 6, 7, 15, 7, 12, 6, 1, 0) time.strptime(" 2005-06-07 15:07:12 EEST", "%Y-%m-%d %H:%M:%S %Z")
(2005, 6, 7, 15, 7, 12, 6, 1, 1)

wi******@hotmai l.com wrote: In your case it is the EEST, as this is the DST timezone (see again:
http://docs.python.org/lib/module-time.html)

** martin@ubuntu:~ $ python
** Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
** [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
** Type "help", "copyright" , "credits" or "license" for more
information.
** >>> import time
** >>> print time.tzname
** ('CET', 'CEST')
** >>> time.strptime(" 2005-06-07 15:07:12 CET", "%Y-%m-%d %H:%M:%S %Z")
** (2005, 6, 7, 15, 7, 12, 1, 158, 0)
** >>> time.strptime(" 2005-06-07 15:07:12 CEST", "%Y-%m-%d %H:%M:%S
%Z")
** (2005, 6, 7, 15, 7, 12, 1, 158, 1)
** >>>

--
Best regards,
Maksim Kasimov
mailto: ka*****@i.com.u a
Jul 19 '05 #6
The names are at least platform specific, see below the names of the
timezones on my Windows NT 4 box

*** Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32
*** Type "help", "copyright" , "credits" or "license" for more
information.
*** >>> import time
*** >>> print time.tzname
*** ('W. Europe Standard Time', 'W. Europe Daylight Time')
*** >>>

Jul 19 '05 #7
yes, i agree, on my WinXP it gives another values.

but my question is how to setup the python (or OS) to make it gives the same results when i call
time.strptime(" 2005-06-07 15:07:12", "%Y-%m-%d %H:%M:%S")
on various servers (and maybe with various OS)?

for now, i can't get it even with the same OS.
and i would like to set time string exactly as "2005-06-07 15:07:12", without "CEST", "EEST" and so on, because as you've notice before, it is different on a variuos systems
wi******@hotmai l.com wrote:
The names are at least platform specific, see below the names of the
timezones on my Windows NT 4 box

*** Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32
*** Type "help", "copyright" , "credits" or "license" for more
information.
*** >>> import time
*** >>> print time.tzname
*** ('W. Europe Standard Time', 'W. Europe Daylight Time')
*** >>>

--
Best regards,
Maksim Kasimov
mailto: ka*****@i.com.u a
Jul 19 '05 #8
It is probably the best to calculate back to UTC.

Assume "2005-06-07 15:07:12" the local time, then convert it as
follows to UTC. Use the UTC time to store/manipulate/whatever you want
to do.

import time
t = time.mktime(tim e.strptime("200 5-06-07 15:07:12", "%Y-%m-%d
%H:%M:%S"))

print time.ctime(t)

offset = time.timezone
if time.daylight:
offset = time.altzone
t += offset
print time.ctime(t)

Jul 19 '05 #9

maybe you are right, i've searched in google groups - such a question was posted to comp.lang.pytho n many times and i has not found (yet) the answer on "how to tune up the output of time.strptime() ?"
wi******@hotmai l.com wrote:
It is probably the best to calculate back to UTC.

Assume "2005-06-07 15:07:12" the local time, then convert it as
follows to UTC. Use the UTC time to store/manipulate/whatever you want
to do.

import time
t = time.mktime(tim e.strptime("200 5-06-07 15:07:12", "%Y-%m-%d
%H:%M:%S"))

print time.ctime(t)

offset = time.timezone
if time.daylight:
offset = time.altzone
t += offset
print time.ctime(t)

--
Best regards,
Maksim Kasimov
mailto: ka*****@i.com.u a
Jul 19 '05 #10

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

Similar topics

3
18205
by: Lukas Kasprowicz | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Folks, My Proglem is, I get after a query on a mysql database with module MySQLdb a tuple but I need this output from database as a string. can anybody help? - -------------- database ---------
3
507
by: Jonas Galvez | last post by:
If I have a tuple like this: (year, month, day, hour, minute) Is there a way to automatically generate a string like this? "YYYY-MM-DDTHH:MM:00" I remember seeing something about it somewhere... wanted to be sure.
1
8539
by: Jinming Xu | last post by:
Hello everyone, While embedding my C++ program with Python, I am impeded by the conversion from a Python Tuple to a C++ array. I hope to get some assistance from you guys. I have a sequence of float numbers to be passed from Python to C++, with indefinite size. So I chose to use Tuple on the Python side. Since PyArg_ParseTuple() has no appropriate format to parse Tuple (The Tuple I am saying is not the Tuple of arguments) of...
3
6061
by: beliavsky | last post by:
Using Python 2.4 on Windows, for me the command print os.stat("temp.txt") gives 1115478343 , which is "seconds since the epoch". How can I get the modification time in a format such as
5
10604
by: kpp9c | last post by:
Hi, I was looking at python & datetime and hoping that it would already have a method/func to translate time formats. I need to translate seconds to hh:mm:ss.ms and vice versa and would like the ability to do some basic arithmetic in these formats. I think that there just has to be a package or module out there that already does this with reasonable speed and accuracy.
5
2367
by: fff_afafaf | last post by:
Do you know is it possible to put different kinds of tuples to one container? E.g. to a vector? (The lengths of the tuples are different, and also the types in the tuples are different.. -Is it possible to make a pointer, which can point to all of these tuples?) #include <tr1/tuple>
14
4211
by: Dave Rahardja | last post by:
Is there a way to generate a series of statements based on the data members of a structure at compile time? I have a function that reverses the endianness of any data structure: /// Reverse the endianness of a data structure "in place". template <typename T> void reverseEndian(T&); Using boost, it is possible to provide the default implementation for all POD
2
5430
by: barronmo | last post by:
I'm trying to get the difference in dates using the time module rather than datetime because I need to use strptime() to convert a date and then find out how many weeks and days until that date. I'm a beginner so any help would be appreciated. Here is the code: def OBweeks(ptID): qry = 'SELECT short_des FROM problems WHERE patient_ID = %s;' % (ptID) results = EMR_utilities.getAllData(qry) for items in results:
3
3935
by: Daniel | last post by:
I have a list of strings, which I need to convert into tuples. If the string is not in python tuple format (i.e. "('one', 'two')", "("one", 'two')", etc.), then I can just make it a 1-tuple (i.e. return (string,) ). If it is in python tuple format, I need to parse it and return the appropriate tuple (it's ok to keep all tuple elements as strings). I think eval() will work for this, but I don't know what will be in the string, so I...
0
9519
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
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
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
6780
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
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.