I am storing a datetime
string in a database. Now I face a problem. When I fetch the string from the database, I need to convert it back to a datetime
object...
Any easy way to do that?
The string of datetime looks like:
2010-11-13 10:33:54.227806
Using the datetime() Pass the year, month and day values of the desired date object (as my_date. year, my_date. month, my_date. day) to this constructor to convert a date object to datetime object.
Example taken from the documentation: parse('10/14/2011 11:46 AM'); String myDtString = dt. format(); system. assertEquals(myDtString, '10/14/2011 11:46 AM'); This example uses parse to create a Datetime from a date passed in as a string and that is formatted for the English (United States) locale.
print(new DateFormat('yyyy/MM/dd'). parse(null)); That's how to parse a String to a DateTime in Dart.
You want datetime.strptime(date_string, format).
from datetime import datetime
datetime.strptime("2010-11-13 10:33:54.227806", "%Y-%m-%d %H:%M:%S.%f")
For details on the format string, see http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With