How to use Python to calculate time

前端 未结 5 1017
傲寒
傲寒 2021-02-05 22:32

I want to write python script that acts as a time calculator.

For example:

Suppose the time is now 13:05:00

I want to add 1 hour, 23 minutes, and 10 seco

5条回答
  •  遇见更好的自我
    2021-02-05 23:01

    Look at mx.DateTime, and DateTimeDelta in particular.

    import mx.DateTime
    d = mx.DateTime.DateTimeDelta(0, 1, 23, 10)
    x = mx.DateTime.now() + d
    x.strftime()
    

    Keep in mind that time is actually a rather complicated thing to work with. Leap years and leap seconds are just the beginning...

提交回复
热议问题