Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. import datetime
  2. import sys
  3. import pytz
  4. et=123123123
  5. tf=12
  6. tz='CET'
  7. tz_dict= {-12: 'BIT',
  8. -11: 'NUT',
  9. -10: ['CKT', 'HST', 'TAHT'],
  10. -9: ['AKST', 'GAMT'],
  11. -8: ['CIST', 'PST'],
  12. -7: 'MST',
  13. -6: ['CST', 'EAST', 'GALT'],
  14. -5: ['ACT', 'COT', 'ECT', 'EST', 'PET'],
  15. -4: ['AMT', 'AST', 'BOT', 'CLT', 'FKT', 'GYT', 'PYT', 'VET'],
  16. -3: ['ART', 'BRT', 'GFT', 'PMST', 'ROTT', 'UYT'],
  17. -2: ['FNT', 'GST'],
  18. -1: ['AZOT', 'CVT', 'EGT'],
  19. 0: ['GMT','UTC', 'WET'],
  20. 14: ['LINT'],
  21. 13: ['PHOT', 'TKT', 'TOT'],
  22. 12: ['FJT', 'GILT', 'MAGT', 'MHT', 'NZST', 'PETT', 'TVT', 'WAKT'],
  23. 11: ['KOST', 'MIST', 'NCT', 'NFT', 'PONT', 'SAKT', 'SBT', 'SRET', 'VUT'],
  24. 10: ['AEST', 'CHST', 'CHUT', 'DDUT', 'PGT', 'VLAT'],
  25. 9: ['EIT', 'JST', 'KST', 'TLT', 'YAKT'],
  26. 8: ['AWST', 'BDT', 'CHOT', 'CIT', 'CT', 'HKT', 'IRKT', 'MYT', 'PHT', 'SGT', 'SST', 'ULAT', 'WST'],
  27. 7: ['CXT', 'DAVT', 'HOVT', 'ICT', 'KRAT', 'THA', 'WIT'],
  28. 6: ['BIOT', 'BST', 'BTT', 'KGT', 'OMST', 'VOST'],
  29. 5: ['HMT', 'MAWT', 'MVT', 'ORAT', 'PKT', 'TFT', 'TJT', 'TMT', 'UZT', 'YEKT'],
  30. 4: ['AZT', 'GET', 'MUT', 'RET', 'SAMT', 'SCT', 'VOLT'],
  31. 3: ['EAT', 'FET', 'IOT', 'MSK', 'SYOT', 'TRT'],
  32. 2: ['CAT', 'EET', 'IST', 'SAST', 'USZ1'],
  33. 1: ['CET', 'MET', 'WAT', 'WEST'],
  34. }
  35.  
  36. def main():
  37. unixConverter(et) #convert epoch to timestamp with 24 hours
  38.  
  39. def unixConverter(et):
  40. """The unix_converter function uses the datetime library to convert the timestamp
  41. :parameter timestamp: An integer representation of a UNIX timestamp.
  42. :return: A human-readable date & time string."""
  43. date_ts = datetime.datetime.utcfromtimestamp(et) #assign datetime to variable and format it
  44. if tf == 24:
  45. print('The current UTC time in 24 hour format is '+ str(date_ts)) #printing!
  46. else:
  47. print('The current UTC time in 12 hour format is '+ date_ts.strftime('%d-%m-%Y %I:%M:%S %p UTC')) #time format isn't 24 hours. falling back to default
  48.  
  49. for tf, value, in tz_dict.items():
  50. if tz in value:
  51. offset = (tf * 3600)
  52. print("The timezone " + str(tz) + " was found. The offset is UTC " +str(tf) + " hours")
  53. print('The offset in seconds is ' + str(offset) + 'seconds')
  54. print('This means that the LOCAL time is '+ str(et)+str(tf) )
  55.  
  56. exit()
  57.  
  58. else:
  59. print("Your timezone wasn't found. Are you sure it exists?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement