Aayco

Creation Date (Discord)

May 17th, 2025
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. from datetime import datetime, timezone
  2. def id_to_unix(id_chan):
  3.     id_chan = int(id_chan)
  4.     return (id_chan >> 22) + 1420070400000
  5. def creation_time(date_time):
  6.     now = datetime.now(timezone.utc)
  7.     delta = now - date_time
  8.     seconds = int(delta.total_seconds())
  9.     minutes = seconds // 60
  10.     hours = minutes // 60
  11.     days = hours // 24
  12.     if days > 0:
  13.         return f"{days} day(s) ago"
  14.     elif hours > 0:
  15.         return f"{hours} hour(s) ago"
  16.     elif minutes > 0:
  17.         return f"{minutes} minute(s) ago"
  18.     else:
  19.         return "just now"
  20. def creation(id_chan):
  21.     unix_ms = id_to_unix(id_chan)
  22.     timestamp = datetime.fromtimestamp(unix_ms / 1000, tz=timezone.utc)
  23.     date24 = timestamp.strftime('%Y-%m-%d, %H:%M:%S')
  24.     date12 = timestamp.strftime('%Y-%m-%d, %I:%M:%S %p')
  25.     local_timezone = datetime.now().astimezone().tzinfo
  26.     ago = creation_time(timestamp)
  27.     print("24-hour format:", date24)
  28.     print("12-hour format:", date12)
  29.     print("Timezone:", local_timezone)
  30.     print("Time ago:", ago)
  31.     print("Raw timestamp (ms):", unix_ms)
  32. creation("1209933715036184597")
  33.  
Advertisement
Add Comment
Please, Sign In to add comment