Date and Time
Python is very useful in case of Date and Time. We can easily retrieve current date and time using Python.
Retrieve Time
To retrieve current time a predefined function localtime() is used. localtime() receives a parameter time.time() . Here,
time is a module,
time() is a function that returns the current system time in number of ticks since 12:00 am , January 1,1970. It is known as epoch.
Tick is simply a floating point number in seconds since epoch.
- import time;
- localtime = time.localtime(time.time())
- print "Current Time is :", localtime
- import calendar
- calendar.prcal(2017)
- import calendar
- print (calendar.isleap(2000))
- import calendar
- print (calendar.monthcalendar(2014,6))
- import calendar
- print (calendar.prmonth(2014,6) )
- import calendar
- print "Current month is:"
- cal = calendar.month(2014, 6)
- print (cal)
- import time
- t = (2014, 6, 26, 17, 3, 38, 1, 48, 0)
- t = time.mktime(t)
- print (time.strftime("%b %d %Y %H:%M:%S", time.gmtime(t)))
No comments:
Post a Comment