dmontgom
asked on
Python - convert string to datetime
Hi,
I have two strings that I want to convert into date and datetimes...
1) 05/15/2009
2) 20 May 2009 23:09:31 -0700
I am going the route of using datetime.datetime.fromtime stamp(time .mktime(ti me.strptim e(dd, "%d %m %Y %H:%M:%S")))
please write the two lines of code that I need for each string I want to convert..
Thanks
I have two strings that I want to convert into date and datetimes...
1) 05/15/2009
2) 20 May 2009 23:09:31 -0700
I am going the route of using datetime.datetime.fromtime
please write the two lines of code that I need for each string I want to convert..
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What if the -0700 Is dymanic? If it is not always -0700?
Then you would have to remove it...
That part of a date stamp is the local offset from GMT, so should stay the same, unless you are moving your machine.
One way to remove it would be shown below.
Thanks for the grade & points.
Good luck & have a great day
That part of a date stamp is the local offset from GMT, so should stay the same, unless you are moving your machine.
One way to remove it would be shown below.
Thanks for the grade & points.
Good luck & have a great day
>>> ds = '20 May 2009 23:09:31 -0700'
>>> ds = ' '.join( ds.split( ' ' )[ 0:-1 ] )
>>> ds
'20 May 2009 23:09:31'
>>>
I don't see anything that allows/supports the -700 though
Open in new window