def str2datetime(s):
#28 May 2008 12:38:16 BDT
return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
#.... some code here....
print repr(pd)
print str2datetime(pd)
Result:
'24 May 2008 12:38:16 BDT'
Traceback (most recent call last):
File "__init__.py", line 40, in <module>
print ssc.get_order_data('202-9810306-3236320')
File
"/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py",
line 306, in get_order_data
print str2datetime(pd)
File
"/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py",
line 299, in str2datetime
return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
File "/usr/local/lib/python2.5/_strptime.py", line 331, in strptime
(data_string, format))
ValueError: time data did not match format: data=24 May 2008 12:38:16
BDT fmt=%d %b %Y %H:%M:%S %Z
I think that the format is correct. What am I doing wrong?
Thanks,
Laszlo 4 1413
On May 27, 10:34*am, Laszlo Nagy <gand...@shopzeus.comwrote:
* * * * * * def str2datetime(s):
* * * * * * * * #28 May 2008 12:38:16 BDT
* * * * * * * * return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
* * * * * * #.... some code here....
* * * * * * print repr(pd)
* * * * * * print str2datetime(pd)
Result:
'24 May 2008 12:38:16 BDT'
Traceback (most recent call last):
* File "__init__.py", line 40, in <module>
* * print ssc.get_order_data('202-9810306-3236320')
* File
"/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py",
line 306, in get_order_data
* * print str2datetime(pd)
* File
"/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py",
line 299, in str2datetime
* * return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
* File "/usr/local/lib/python2.5/_strptime.py", line 331, in strptime
* * (data_string, format))
ValueError: time data did not match format: *data=24 May 2008 12:38:16
BDT *fmt=%d %b %Y %H:%M:%S %Z
I think that the format is correct. What am I doing wrong?
Thanks,
* *Laszlo
I tried taking out components until I got it to work. It seems to be
choking on the time zone part of it. If you remove the "BDT" from your
string and the "%Z" from your formatter, it works. Unfortunately, I do
not know why it doesn't work the other way.
Mike
Out of curiosity -- just what zone /is/ "BDT"... The only thing that
comes to mind is a type for "BST" (British Summer Time)
I think you are right. This date string was taken from a .co.uk site. :-)
My fault. It was a 3 letter code after a date, I was sure that it is a
time zone. Apparently, it is not. :-)
The "did not match format" message was misleading me. It would be better
to throw ValueError("Unknown time zone: BDT"). :-)
Thank you,
Laszlo
Am Tue, 27 May 2008 12:37:34 -0700 schrieb Dennis Lee Bieber:
>
From the library reference:
"""
Support for the %Z directive is based on the values contained in tzname
and whether daylight is true. Because of this, it is platform-specific
except for recognizing UTC and GMT which are always known (and are
considered to be non-daylight savings timezones). """
The only value that passed for me was UTC (I didn't try GMT) but...
For me, only UTC, GMT, CET and CEST (Central European [Summer] Time) work.
My time.tzname is ('CET', 'CEST').
I think the documentation must be read that ***only***
UTC,GMT,time.tzname work.
Also, time zone names are not unique: EST can be Eastern Summer Time (US)
as well as Eastern Summer Time (Australia).
For working with time zones, I think that a module like pytz http://pytz.sourceforge.net/
may be better suited.
My 0.02c.
Martin
On May 28, 12:19*pm, mblume <mbl...@socha.netwrote:
Am Tue, 27 May 2008 12:37:34 -0700 schrieb Dennis Lee Bieber:
* *From the library reference:
"""
Support for the %Z directive is based on the values contained in tzname
and whether daylight is true. Because of this, it is platform-specific
except for recognizing UTC and GMT which are always known (and are
considered to be non-daylight savings timezones). """
* *The only value that passed for me was UTC (I didn't try GMT) but....
For me, only UTC, GMT, CET and CEST (Central European [Summer] Time) work.
My time.tzname is ('CET', 'CEST').
I think the documentation must be read that ***only***
UTC,GMT,time.tzname work.
Also, time zone names are not unique: EST can be Eastern Summer Time (US)
as well as Eastern Summer Time (Australia).
For working with time zones, I think that a module like pytzhttp://pytz.sourceforge.net/
may be better suited.
My 0.02c.
Martin
Yeah. The timezone part of Python's time module is probably it's
weakest link. There was a pretty long thread about it about a year
ago. Maybe 2.6 or the 3.0 branch will make it a little more friendly.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: python |
last post by:
Hi-
I'm getting a "DeprecationWarning: integer argument expected, got float"
warning with mx.DateTime and I can't figure out why. Can anyone help me
out?
This code:
import mx.DateTime
|
by: Max M |
last post by:
# -*- coding: latin-1 -*-
"""
I am currently using the datetime package, but I find that the design is
oddly
asymmetric. I would like to know why. Or perhaps I have misunderstood
how it...
|
by: Mingus Tsai |
last post by:
Hello- please help with unpickling problem:
I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows
XPhome system.
My problem is with using cPickle to deserialize my pickled...
|
by: Fritz Switzer |
last post by:
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.
For example:
DateTime.Now.AddMinutes(30) returns "00:30"
...
|
by: I am Sam |
last post by:
I have created this DateTime object and instanced it I think correctly
DateTime myClubNow1=new...
|
by: nobody |
last post by:
I know that given a FormatString and a DateTime you can use
DateTime.ToString(...) to convert the DateTime to a String. My question is
how can you turn that around? Given a String and a...
|
by: Phil B |
last post by:
I am having a problem with a datetime from a web services provider
The provider is sending the following SOAP response
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope...
|
by: JFieseler |
last post by:
Hi all,
in a huge project i have the following problem.
I create an object which contains many private members (i know that this is
not correct, but it is a single use migration program). The...
|
by: js |
last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss".
I need to parse the text using System.DateTime.Parse() function with
custom format. I got an error using the following code. ...
|
by: James |
last post by:
Hello,
I am a beginner in C# programming and I just want to know how we can
pass a datetime variable in a method. can anyone please help me
regarding this.
Thanks,
James.
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
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...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
| |