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

datetime.time() class - How to pass it a time string?

Hi,

I have a string in the following format:

"00:00:25.886411"

I would like to pass this string into the datetime.time() class and
have it parse the string and use the values. However, the __init__()
method only takes integers (which means I'd be forced to parse the
string myself). Does anyone know of a way I can make it use the
string? Thanks.

Jul 24 '07 #1
3 2595
On 7/24/07, Robert Dailey wrote:
Hi,

I have a string in the following format:

"00:00:25.886411"

I would like to pass this string into the datetime.time() class and
have it parse the string and use the values. However, the __init__()
method only takes integers (which means I'd be forced to parse the
string myself). Does anyone know of a way I can make it use the
string? Thanks.
timestr = "00:00:25.886411"
timesep = re.compile('[:.]')
datetime.time(*[int(i) for i in timesep.split(timestr)])
Jul 24 '07 #2
On 24 ec, 19:11, Robert Dailey <rcdai...@gmail.comwrote:
Hi,

I have a string in the following format:

"00:00:25.886411"

I would like to pass this string into the datetime.time() class and
have it parse the string and use the values. However, the __init__()
method only takes integers (which means I'd be forced to parse the
string myself). Does anyone know of a way I can make it use the
string? Thanks.
http://pleac.sourceforge.net/pleac_p...sandtimes.html
the part "http://pleac.sourceforge.net/pleac_python/
datesandtimes.html"
HTH
Petr Jakes

Jul 24 '07 #3
En Tue, 24 Jul 2007 14:37:20 -0300, Miles <se*********@gmail.comescribió:
On 7/24/07, Robert Dailey wrote:
>I have a string in the following format:

"00:00:25.886411"

I would like to pass this string into the datetime.time() class and
have it parse the string and use the values. However, the __init__()
method only takes integers (which means I'd be forced to parse the
string myself). Does anyone know of a way I can make it use the
string? Thanks.

timestr = "00:00:25.886411"
timesep = re.compile('[:.]')
datetime.time(*[int(i) for i in timesep.split(timestr)])
That's OK if one can always guarantee the 6 digits after the decimal
point; else a bit more work is required:

pytimestr = "00:00:25.886"
pyh, m, s = timestr.split(":")
pyif '.' in s:
.... s, us = s.split('.')
.... us = us[:6].ljust(6, '0')
.... else:
.... us = 0
....
pydatetime.time(int(h), int(m), int(s), int(us))
datetime.time(0, 0, 25, 886000)

--
Gabriel Genellina

Jul 25 '07 #4

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

Similar topics

2
by: A Programmer | last post by:
I can't believe I have never run into this before but, I have an object that has a property of type DateTime. A collection of these objects are used to populate my DataGrid. In DateTime format they...
2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
9
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...
9
by: piersh | last post by:
Does anyone know how to make the following method work across timezones? public DateTime GetTime () { return DateTime.UtcNow; }
5
by: ns21 | last post by:
Our application is windows desktop application. We are using VS.Net 2003, C#, Framework 1.1, SQL 2000. We use webservices to add/update/select objects. We are using XML Serialization. Following is...
3
by: insyte | last post by:
With assistance from Gabriel and Frederik (and a few old threads in c.l.p.) I've been making headway on my specialized datetime class. Now I'm puzzled by behavior I didn't expect while attempting...
1
by: Brad Pears | last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field of type "smalldatetime". In my vb application, the user may or may not enter a date value into the appropriate text box....
1
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.