0% found this document useful (0 votes)
133 views2 pages

Python Date and Time Function

This Python script contains a dateandtime function that takes an integer value and tuple as parameters. Based on the integer value, it performs different datetime operations like formatting a date, converting a timestamp to a date, getting the hour from a time, or formatting a full datetime with date, time and returns the result(s) in a list. It accepts user input to call the function with different parameters and display the output.

Uploaded by

sach
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views2 pages

Python Date and Time Function

This Python script contains a dateandtime function that takes an integer value and tuple as parameters. Based on the integer value, it performs different datetime operations like formatting a date, converting a timestamp to a date, getting the hour from a time, or formatting a full datetime with date, time and returns the result(s) in a list. It accepts user input to call the function with different parameters and display the output.

Uploaded by

sach
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#!

/bin/python3

import math
import os
import random
import re
import sys

import datetime
# Complete the 'dateandtime' function below.
#
# The function accepts INTEGER val as parameter.
# The return type must be LIST.
def dateandtime(val,tup):
list1=[]
if val == 1:
time1 = datetime.date(tup[0],tup[1],tup[2]).strftime("%d/%m/%Y")
list1.append(datetime.date(tup[0],tup[1],tup[2]))
list1.append(time1)
elif val == 2:
time1 = datetime.date.fromtimestamp(tup[0])
list1.append(time1)
elif val == 3:
time1 = datetime.time(tup[0],tup[1],tup[2])
list1.append(time1.strftime("%I"))
elif val == 4:
time1 = datetime.date(tup[0],tup[1],tup[2])
list1.append(time1.strftime("%A"))
list1.append(time1.strftime("%B"))
list1.append(time1.strftime("%j"))
elif val == 5:
time1 = (datetime.datetime(tup[0],tup[1],tup[2],tup[3],tup[4],tup[5]))
list1.append(time1)
return list1

if __name__ == '__main__':
val = int(input().strip())

if val ==1 or val==4 or val ==3:


qw1_count=3
if val==2:
qw1_count=1
if val ==5:
qw1_count=6
qw1 = []

for i in range(qw1_count):
qw1_item = int(input().strip())
qw1.append(qw1_item)

tup=tuple(qw1)

ans = dateandtime(val,tup)

print(ans)

'''inputs
1
2019
4
13
------------------
2
1258094605'''

You might also like