IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Using pendulum in Python

    RobinDong发表于 2022-12-15 00:22:52
    love 0

    pendulum is a prevalent python library in my company. For example, if I want to get the time of the previous Monday, it could be written:

    pendulum.today("US/Pacific").previous(pendulum.MONDAY)
    # return type "pendulum.datetime.DateTime`

    But this will return a class of pendulum.datetime.DateTime. What if I wish Date instead of pendulum.datetime.DataTime? Actually, the pendulum.datetime.DateTime inherited from datetime.datetime so we can use .date():

    pendulum.today("US/Pacific").previous(pendulum.MONDAY).date()
    # return type "pendulum.datetime.Date`


沪ICP备19023445号-2号
友情链接