473,386 Members | 1,652 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,386 software developers and data experts.

How to parse this timestamp?

I've got timestamps in a file that look like:

[19-Aug-2007 07:38:43+216ms NZST]

How can I parse them? I don't see any way to build a strftime()
format string that can handle the +216ms part. The best I can see is
tearing it all apart with a regex, but I'm trying to avoid that pain
if I can.

(PS: I have no clue why google groups thinks it should put
"gnu.gcc.help" on the from line)

Mar 12 '08 #1
2 2377
Hello,
[19-Aug-2007 07:38:43+216ms NZST]

How can I parse them? *I don't see any way to build a strftime()
format string that can handle the +216ms part. The best I can see is
tearing it all apart with a regex, but I'm trying to avoid that pain
if I can.

(PS: I have no clue why google groups thinks it should put
"gnu.gcc.help" on the from line)
Just zap the end and use time.strptime:
>>s = '19-Aug-2007 07:38:43+216ms NZST'
strptime(re.sub("\+\d{3}ms [A-Z]{4}", "", s), "%d-%b-%Y %H:%M:%S")
(2007, 8, 19, 7, 38, 43, 6, 231, -1)
>>>
HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Mar 12 '08 #2
gnu.gcc.help schrieb:
I've got timestamps in a file that look like:

[19-Aug-2007 07:38:43+216ms NZST]

How can I parse them? I don't see any way to build a strftime()
format string that can handle the +216ms part. The best I can see is
tearing it all apart with a regex, but I'm trying to avoid that pain
if I can.

(PS: I have no clue why google groups thinks it should put
"gnu.gcc.help" on the from line)
Then don't use the regexes. Use string.split to separate the string on
the +, then parse the left part with strptime, and usp pytz and
datetime.timedelta to do the rest.

Diez
Mar 12 '08 #3

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

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
2
by: rong.guo | last post by:
Hello Group, I am having a really weird problem... Can anyone tell the difference between Query 1 and Query 2 below? Why Query 2 excludes '2/28/2005'? Many thanks! create table a...
10
by: Reiner Merz | last post by:
Hi, I'm looking for advice on how to parse a timestamp string according to the ISO 8601 specification. For those unfamiliar with the standard, here's an example: 2003-09-09T23:00:00Z...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples...
22
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
4
by: sturnfie | last post by:
Hey all, I recently came across the xml.sax libraries and am trying to use them. I am currently making a string variable, and am attempting to pass it into a parser instance as follows: def...
7
by: JJ | last post by:
How do I set one field to have the updated timestamp, and another to have the created timestamp? I want to do this directly from code generated from DB Designer if possible?! JJ
0
by: rahul gupta | last post by:
hi all i got stucked in 1 problem.i am getting err (java.text.ParseException: Unparseable date: "2007-06-29 11:34:59.0") on this line--utilDate = format.parse(convert); code is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.