471,853 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

Get System Date?

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.

Feb 5 '06 #1
5 10752
Dustan:
Is it possible to get the system date on a Windows XP machine?


Most certainly:
http://www.python.org/doc/lib/module-time.html

--
René Pijlman
Feb 5 '06 #2
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:
import time
now = time.localtime()
print now

(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

Feb 5 '06 #3
Thanks

Feb 5 '06 #4
Dustan <Du**********@gmail.com> wrote:
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.

import datetime
x=datetime.date.today()
yyyy, mm, dd = x.year, x.month, x.day
print yyyy 2006 print mm 2 print dd 5


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
Feb 5 '06 #5
Dave wrote:
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...
import datetime
datetime.datetime.now()

datetime.datetime(2006, 2, 5, 23, 1, 45, 569833)
Feb 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by NicK chlam via DotNetMonster.com | last post: by
11 posts views Thread by Mike9900 | last post: by
3 posts views Thread by Carlos Lozano | last post: by
15 posts views Thread by iffa n wanie | last post: by
4 posts views Thread by anagai | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.