Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, timezone
- def id_to_unix(id_chan):
- id_chan = int(id_chan)
- return (id_chan >> 22) + 1420070400000
- def creation_time(date_time):
- now = datetime.now(timezone.utc)
- delta = now - date_time
- seconds = int(delta.total_seconds())
- minutes = seconds // 60
- hours = minutes // 60
- days = hours // 24
- if days > 0:
- return f"{days} day(s) ago"
- elif hours > 0:
- return f"{hours} hour(s) ago"
- elif minutes > 0:
- return f"{minutes} minute(s) ago"
- else:
- return "just now"
- def creation(id_chan):
- unix_ms = id_to_unix(id_chan)
- timestamp = datetime.fromtimestamp(unix_ms / 1000, tz=timezone.utc)
- date24 = timestamp.strftime('%Y-%m-%d, %H:%M:%S')
- date12 = timestamp.strftime('%Y-%m-%d, %I:%M:%S %p')
- local_timezone = datetime.now().astimezone().tzinfo
- ago = creation_time(timestamp)
- print("24-hour format:", date24)
- print("12-hour format:", date12)
- print("Timezone:", local_timezone)
- print("Time ago:", ago)
- print("Raw timestamp (ms):", unix_ms)
- creation("1209933715036184597")
Advertisement
Add Comment
Please, Sign In to add comment