Get System Date?

D

Dustan

Is it possible to get the system date on a Windows XP machine? Most
Convenient would to retrieve YYYY, MM, and DD as seperate variables.

When I say system date, I'm thinking of the small clock in the
lower-right hand corner, which has date as well as time, but if there's
another clock that Python supports, it works for me as long as it's
somewhat accurate.
 
D

Dave

Dustan,

Python has a module called, appropriately, "time". Like most things in
Python, it's fairly simple and straightforward to use.

The module is documented here:
http://docs.python.org/lib/module-time.html

Breifly, though, the format you want is built right into time:
(2006, 2, 5, 13, 21, 15, 6, 36, 0)

So to get the year, month, and day you would just have to manipulate
the values returned by time.gmtime().

- Dave
 
A

Alex Martelli

Dustan said:
Is it possible to get the system date on a Windows XP machine? Most
Convenient would to retrieve YYYY, MM, and DD as seperate variables.

When I say system date, I'm thinking of the small clock in the
lower-right hand corner, which has date as well as time, but if there's
another clock that Python supports, it works for me as long as it's
somewhat accurate.

As you see, these are integers (so, for example, mm is not '02' but just
2). Pretty easy to make them into strings, of course, if you want.


Alex
 
M

Magnus Lycka

Dave said:
Dustan,

Python has a module called, appropriately, "time".

This is basically a wrapper around the standard C time
library. Python has a more modern and spiffy datetime
module which isn't restrained to 1970-2038, and just
handles spiffy date and datetime objects instead of
making you deal with awkward conversions between strange
numbers and obscure tuples. The old time module does work,
but due to e.g. strange assymetries in the module, you
have to deal with strange quirks to convert UTC times
right...
datetime.datetime(2006, 2, 5, 23, 1, 45, 569833)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top