Python中时间处理常用函数大全
Python中时间处理常用函数大全:
1. time.time():返回当前时间的Unix时间戳,以秒为单位。
2. time.localtime([secs]):将一个Unix时间戳转换为本地时间。如果不指定参数,则返回当前时间。
3. time.strftime(format[, t]):根据指定的格式化字符串将时间格式化成字符串。
4. time.strptime(string[, format]):根据指定的格式将字符串解析为时间。
5. time.mktime(t):将一个时间转换为Unix时间戳。
6. datetime.datetime.now():返回当前时间的datetime对象。
7. datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]]):创建一个表示指定日期和时间的datetime对象。
8. datetime.datetime.fromtimestamp(timestamp[, tz]):将一个Unix时间戳转换为datetime对象。
9. datetime.datetime.strptime(date_string, format):根据指定的格式将字符串解析为datetime对象。
10. datetime.datetime.strftime(format):根据指定的格式将datetime对象格式化成字符串。
11. datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]):表示一个时间间隔。
12. datetime.timedelta.total_seconds():返回一个时间间隔的总秒数。
13. datetime.timedelta.days:返回时间间隔中的天数。
14. datetime.timedelta.seconds:返回时间间隔中的秒数。
15. datetime.timedelta.microseconds:返回时间间隔中的微秒数。
16. datetime.timedelta.min:返回时间间隔的最小值。
17. datetime.timedelta.max:返回时间间隔的最大值。
18. datetime.timedelta.resolution:返回时间间隔的最小粒度。
19. datetime.date.today():返回当前日期。
20. datetime.date(year, month, day):创建一个表示指定日期的date对象。
21. datetime.date.fromtimestamp(timestamp):将一个Unix时间戳转换为date对象。
22. datetime.date.strftime(format):根据指定的格式将date对象格式化成字符串。
23. datetime.date.fromisoformat(date_string):根据ISO 8601格式将字符串解析为date对象。
24. datetime.date.isoweekday():返回目标日期的星期几,星期一返回1,星期二返回2,以此类推。
25. datetime.time(hour[, minute[, second[, microsecond[, tzinfo]]]]):创建一个表示指定时间的time对象。
26. datetime.time.fromtimestamp(timestamp[, tz]):将一个Unix时间戳转换为time对象。
27. datetime.time.isoformat(timespec='auto'):返回time对象的ISO 8601格式字符串。
28. datetime.time.strftime(format):根据指定的格式将time对象格式化成字符串。
29. datetime.time.replace([hour[, minute[, second[, microsecond[, tzinfo]]]]]):返回一个新的time对象,将指定的时间部分替换为新值。
30. datetime.datetime.combine(date, time):将一个date对象和一个time对象合并为一个datetime对象。
这只是一部分Python中时间处理的常用函数,还有很多其他的函数可以用来处理时间。希望以上内容对您有所帮助。
