Python ProgrammingPython Programming

Displays the current date and time using time module

Develop a program that displays the current time and date in various format. Convert number of seconds in GMT time. You have to use asctime in the time module, it reads current date and time from computer's internal clock.
##
#Python's program that displays the current time and date in various format.

#import time module
import time
from time import gmtime, strftime

t = time.localtime()
print (time.asctime(t))
print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
print(strftime("%A", gmtime()))
print(strftime("%D", gmtime()))
print(strftime("%B", gmtime()))
print(strftime("%y", gmtime()))

# Convert seconds into GMT date
print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime(1234567890)))
Sample output of above program.
C:\Python\programs>python program.py
Sun May 7 09:30:37 2017
Sun, 07 May 2017 04:00:37 +0000
Sunday
05/07/17
May
17
Fri, 13 Feb 2009 23:31:30 +0000
C:\Python\programs>