I'm calling an IronPython script and passing it a .NET object that contains a DateTime
structure.
I'm trying to use IronPython's JSON support to serialize the object as JSON.
Everything works great until I encounter the .NET DateTime
.
How do I convert from the .NET DateTime
to the IronPython datetime
?
You can use the datetime module's combine method to combine a date and a time to create a datetime object. If you have a date object and not a time object, you can initialize the time object to minimum using the datetime object(minimum time means midnight).
Python datetime. date(year, month, day) :MINYEAR <= year <= MAXYEAR. 1 <= month <= 12. 1 <= day <= number of days in the given month and year.
Python strftime() function is present in datetime and time modules to create a string representation based on the specified format string.
Anticipating that people might like to convert between these we actually make it really easy:
import datetime
from System import DateTime
datetime.datetime(DateTime.Now)
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