We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importosfromdatetimeimportdatetime# Complete the time_delta function below.deftime_delta(t1,t2):# Define the date formatdate_format="%a %d %b %Y %H:%M:%S %z"# Parse the input strings into datetime objectsdt1=datetime.strptime(t1,date_format)dt2=datetime.strptime(t2,date_format)# Calculate the absolute difference in secondsdelta=abs((dt1-dt2).total_seconds())# Return the result as a stringreturnstr(int(delta))if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')t=int(input())fort_itrinrange(t):t1=input()t2=input()delta=time_delta(t1,t2)fptr.write(delta+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Time Delta
You are viewing a single comment's thread. Return to all comments →