[IronPython] [python] Import Now

Michael Foord fuzzyman at voidspace.org.uk
Sun Oct 7 22:31:29 CEST 2007


Davy Mitchell wrote:
> IronPython console: IronPython 2.0A4 (2.0.10904.02) on .NET 2.0.50727.312
> Copyright (c) Microsoft Corporation. All rights reserved.
>   
>>>> from System.DateTime import Now
>>>> print Now
>>>>         
> 07/10/2007 21:23:20
>   
>>>> print "a few seconds later" + Now.ToString()
>>>>         
> a few seconds later07/10/2007 21:23:20
>   
>>>> from System.DateTime import Now
>>>> print Now
>>>>         
> 07/10/2007 21:24:02
>   
>
> Huh?!??! :-)
>
>   

That's kind of what I would expect. :-)

Now is actually a (static) member of the DateTime class - but in .NET 
you can do this kind of import.

DateTime instances are immutable - so accessing 'Now' returns the 
current one (which doesn't then change). When you import again you 
look-up the new current time.

Just import DateTime and access 'Now' whenever you need it...

Michael
http://www.manning.com/foord



More information about the Ironpython-users mailing list