Python (IronPython) time to .NET C# DateTime format
Today i was trying to use Python (IronPython) time format in .NET, how their was no straight forward way to consume the same in C#.
The trick was to convert the Python time format into .NET format
Here is the code, which i have used:
1: i_tmp = os.path.getatime(path)
2: t_tmp = localtime(i_tmp)
3: tstamp = strftime("%m/%d/%Y %H:%M:%S", t_tmp)
Now you can directly use the same in C#
1: //Sample datetime format from python
2: string str = "11/05/2006 23:54:46";
3: DateTime dt2 = Convert.ToDateTime(str);
1 Comments:
I found an easier way of doing it.
Here is how
Python :
dt=str(datetime.datetime.now())
dt_cs=dt.replace(" ","T")
------------
Now dt_cs=2012-05-01T17:00:20.358376
This format is recognized in C# i.e. DateTime.Parse(dt_cs) in
-Om
Post a Comment
<< Home