Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import sys
- import pytz
- et=123123123
- tf=12
- tz='CET'
- tz_dict= {-12: 'BIT',
- -11: 'NUT',
- -10: ['CKT', 'HST', 'TAHT'],
- -9: ['AKST', 'GAMT'],
- -8: ['CIST', 'PST'],
- -7: 'MST',
- -6: ['CST', 'EAST', 'GALT'],
- -5: ['ACT', 'COT', 'ECT', 'EST', 'PET'],
- -4: ['AMT', 'AST', 'BOT', 'CLT', 'FKT', 'GYT', 'PYT', 'VET'],
- -3: ['ART', 'BRT', 'GFT', 'PMST', 'ROTT', 'UYT'],
- -2: ['FNT', 'GST'],
- -1: ['AZOT', 'CVT', 'EGT'],
- 0: ['GMT','UTC', 'WET'],
- 14: ['LINT'],
- 13: ['PHOT', 'TKT', 'TOT'],
- 12: ['FJT', 'GILT', 'MAGT', 'MHT', 'NZST', 'PETT', 'TVT', 'WAKT'],
- 11: ['KOST', 'MIST', 'NCT', 'NFT', 'PONT', 'SAKT', 'SBT', 'SRET', 'VUT'],
- 10: ['AEST', 'CHST', 'CHUT', 'DDUT', 'PGT', 'VLAT'],
- 9: ['EIT', 'JST', 'KST', 'TLT', 'YAKT'],
- 8: ['AWST', 'BDT', 'CHOT', 'CIT', 'CT', 'HKT', 'IRKT', 'MYT', 'PHT', 'SGT', 'SST', 'ULAT', 'WST'],
- 7: ['CXT', 'DAVT', 'HOVT', 'ICT', 'KRAT', 'THA', 'WIT'],
- 6: ['BIOT', 'BST', 'BTT', 'KGT', 'OMST', 'VOST'],
- 5: ['HMT', 'MAWT', 'MVT', 'ORAT', 'PKT', 'TFT', 'TJT', 'TMT', 'UZT', 'YEKT'],
- 4: ['AZT', 'GET', 'MUT', 'RET', 'SAMT', 'SCT', 'VOLT'],
- 3: ['EAT', 'FET', 'IOT', 'MSK', 'SYOT', 'TRT'],
- 2: ['CAT', 'EET', 'IST', 'SAST', 'USZ1'],
- 1: ['CET', 'MET', 'WAT', 'WEST'],
- }
- def main():
- unixConverter(et) #convert epoch to timestamp with 24 hours
- def unixConverter(et):
- """The unix_converter function uses the datetime library to convert the timestamp
- :parameter timestamp: An integer representation of a UNIX timestamp.
- :return: A human-readable date & time string."""
- date_ts = datetime.datetime.utcfromtimestamp(et) #assign datetime to variable and format it
- if tf == 24:
- print('The current UTC time in 24 hour format is '+ str(date_ts)) #printing!
- else:
- 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
- for tf, value, in tz_dict.items():
- if tz in value:
- offset = (tf * 3600)
- print("The timezone " + str(tz) + " was found. The offset is UTC " +str(tf) + " hours")
- print('The offset in seconds is ' + str(offset) + 'seconds')
- print('This means that the LOCAL time is '+ str(et)+str(tf) )
- exit()
- else:
- print("Your timezone wasn't found. Are you sure it exists?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement