python 获取当年、季度、月、日的开始和结束时间

绝地灬酷狼 2022-06-01 03:38 395阅读 0赞

使用 arrow

  1. class DateUtils(object):
  2. @staticmethod
  3. def get_today_start():
  4. now = arrow.utcnow().to("local")
  5. return now.floor("day")
  6. @staticmethod
  7. def get_today_end():
  8. now = arrow.utcnow().to("local")
  9. return now.ceil("day")
  10. @staticmethod
  11. def get_today_start_end():
  12. return DateUtils.get_today_start(), DateUtils.get_today_end()
  13. @staticmethod
  14. def get_week_start():
  15. now = arrow.utcnow().to("local")
  16. return now.floor("week")
  17. @staticmethod
  18. def get_week_end():
  19. now = arrow.utcnow().to("local")
  20. return now.ceil("week")
  21. @staticmethod
  22. def get_week_start_end():
  23. return DateUtils.get_week_start(), DateUtils.get_week_end()
  24. @staticmethod
  25. def get_month_start():
  26. now = arrow.utcnow().to("local")
  27. return now.floor("month")
  28. @staticmethod
  29. def get_month_end():
  30. now = arrow.utcnow().to("local")
  31. return now.ceil("month")
  32. @staticmethod
  33. def get_month_start_end():
  34. return DateUtils.get_month_start(), DateUtils.get_month_end()
  35. @staticmethod
  36. def get_quarter_start():
  37. now = arrow.utcnow().to("local")
  38. return now.floor("quarter")
  39. @staticmethod
  40. def get_quarter_end():
  41. now = arrow.utcnow().to("local")
  42. return now.ceil("quarter")
  43. @staticmethod
  44. def get_quarter_start_end():
  45. return DateUtils.get_quarter_start(), DateUtils.get_quarter_end()
  46. @staticmethod
  47. def get_year_start():
  48. now = arrow.utcnow().to("local")
  49. return now.floor("year")
  50. @staticmethod
  51. def get_year_end():
  52. now = arrow.utcnow().to("local")
  53. return now.ceil("year")
  54. @staticmethod
  55. def get_year_start_end():
  56. return DateUtils.get_year_start(), DateUtils.get_year_end()

发表评论

表情:
评论列表 (有 0 条评论,395人围观)

还没有评论,来说两句吧...

相关阅读