Skip to content

Instantly share code, notes, and snippets.

@ichux
Last active June 26, 2024 05:02
Show Gist options
  • Save ichux/5f9248ce6f5c2c95411265c3a727f6c8 to your computer and use it in GitHub Desktop.
Save ichux/5f9248ce6f5c2c95411265c3a727f6c8 to your computer and use it in GitHub Desktop.
describe_time
from datetime import datetime
import pytz
UTC = pytz.UTC
WAT = pytz.timezone("Africa/Lagos")
def current_time():
return datetime.now(pytz.utc).strftime("%Y-%m-%d %H:%M:%S %Z%z")
def status(seen_at):
main_time = datetime.strptime(seen_at, "%Y-%m-%d %H:%M:%S %Z%z")
utc = main_time.astimezone(UTC)
wat = main_time.astimezone(WAT)
return utc, wat
if __name__ == "__main__":
first, second = status("2024-06-24 10:33:33 UTC+0000")
print(f"{current_time()}\n")
print(first, first.timestamp(), second, second.timestamp(), sep=" | ")
reverse = datetime.fromtimestamp(first.timestamp(), tz=UTC)
print(reverse.strftime("%Y-%m-%d %H:%M:%S %Z%z"))
print(first.strftime("%Y-%m-%d %H:%M:%S %Z%z"))
print(second.strftime("%Y-%m-%d %H:%M:%S %Z%z"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment