Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert from a .NET DateTime to an IronPython datetime?

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?

like image 530
ScArcher2 Avatar asked Jun 09 '11 17:06

ScArcher2


People also ask

How do I convert a date to a datetime object?

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).

How do I convert datetime to days in Python?

Python datetime. date(year, month, day) :MINYEAR <= year <= MAXYEAR. 1 <= month <= 12. 1 <= day <= number of days in the given month and year.

Which function converts a datetime object to a string?

Python strftime() function is present in datetime and time modules to create a string representation based on the specified format string.


1 Answers

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)
like image 179
Dino Viehland Avatar answered Oct 30 '22 14:10

Dino Viehland