import moment from datetime import datetime # Create a moment from a string moment.date("12-18-2012", "M-D-YYYY") # Create a moment with strftime format moment.date("12-18-2012", "%m-%d-%Y") # By default, the "%Y-%m-%d" strftime format is used moment.date("2012-12-18") # Create a moment from the current datetime moment.now() # The moment can also be UTC-based moment.utcnow() # Create a moment with the UTC time zone moment.utc("2012-12-18", "YYYY-M-D") # Create a moment from a Unix timestamp moment.unix(1355875153626) # Create a moment from a Unix UTC timestamp moment.unix(1355875153626, utc=True) # Return a datetime instance moment.date(2012, 12, 18).date # We can do the same thing with the UTC method moment.utc(2012, 12, 18).date # Create and format a moment using Moment.js semantics moment.now().format("YYYY-M-D") # Create and format a moment with strftime semantics moment.date(2012, 12, 18).
python moment 时间处理(较为灵活的时间运算)
最新推荐文章于 2024-04-13 18:00:00 发布