Advertisement
Guest User

Untitled

a guest
Jan 5th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import datetime
  2. import random
  3.  
  4. now = datetime.datetime.now()  # Get the current time in Italy
  5. delta = datetime.timedelta(minutes=random.randint(10, 60))  # Generate a random interval between 10 and 60 minutes
  6. random_time = now - delta  # Subtract the random interval from the current time to get a previous random time
  7. time_diff = now - random_time
  8. hours_diff = time_diff.seconds // 3600
  9. minutes_diff = (time_diff.seconds // 60) % 60
  10.  
  11. if hours_diff == 0:
  12.     time_ago = f"{minutes_diff} minuti fa"
  13. elif hours_diff == 1:
  14.     time_ago = f"1 ora e {minutes_diff} minuti fa"
  15. else:
  16.     time_ago = f"{hours_diff} ore e {minutes_diff} minuti fa"
  17.  
  18. output = [{"random_time": time_ago}]
  19. print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement