![](/style/images/good.png)
![](/style/images/bad.png)
Using pendulum in Python
source link: https://donghao.org/2022/12/15/using-pendulum-in-python/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using pendulum in Python
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`
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`
pendulum.today("US/Pacific").previous(pendulum.MONDAY).date()
# return type "pendulum.datetime.Date`
Related Posts
- A handy Python library
To find an easy way to print the runtime of a function, I found an…
- An error about multiprocessing of Python
Our python program reported errors when running a new dataset: [77 rows x 4 columns]]'.…
- The type of variables in Python
Haven't written python code for more than one year, I met this simple problem: import…
December 15, 2022 - 0:22
RobinDong
develop
python
Leave a comment
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK