Equivalent to DateTime.Now.AddSeconds in IronPython

there is the equivalent of DateTime.Now.AddSeconds() in IronPython , and if it is not, how to achieve it in IronPython ?

+4
source share
1 answer

DateTime is part of the .NET structure from the System namespace. Everything in the structure is almost the same no matter what language you use.

In IronPython, the following are valid:

 import System dt = System.DateTime.Now.AddSeconds(30) 

Below is a screenshot from the console window in the interactive tutorial .

Iron Python Demo 1

The above assumes that you really want to use the .Net System.DateTime object. But if you work a lot in python, you can use the Python DateTime class. In Python, the timedelta class is very similar to the TimeSpan class in .Net:

 from datetime import datetime, timedelta dt = datetime.now() + timedelta(seconds = 30) 

This will work in any python interpreter, including IronPython. Below is another screenshot from the console window in the IronPython interactive tutorial:

Iron Python Demo 2

+3
source

Source: https://habr.com/ru/post/1487756/


All Articles