datetime.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from time import localtime
  2. class date:
  3. def __init__(self, year: int, month: int, day: int):
  4. self.year = year
  5. self.month = month
  6. self.day = day
  7. @staticmethod
  8. def today():
  9. t = localtime()
  10. return date(t.tm_year, t.tm_mon, t.tm_mday)
  11. def __str__(self):
  12. return f"{self.year}-{self.month}-{self.day}"
  13. def __repr__(self):
  14. return f"datetime.date({self.year}, {self.month}, {self.day})"
  15. class datetime(date):
  16. def __init__(self, year: int, month: int, day: int, hour: int, minute: int, second: int):
  17. super(datetime, self).__init__(year, month, day)
  18. self.hour = hour
  19. self.minute = minute
  20. self.second = second
  21. @staticmethod
  22. def now():
  23. t = localtime()
  24. return datetime(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec)
  25. def __str__(self):
  26. return f"{self.year}-{self.month}-{self.day} {self.hour}:{self.minute}:{self.second}"
  27. def __repr__(self):
  28. return f"datetime.datetime({self.year}, {self.month}, {self.day}, {self.hour}, {self.minute}, {self.second})"