Python datetime模块

来源:互联网 发布:网络知名小说家排行榜 编辑:程序博客网 时间:2024/06/06 05:27

Python datetime模块是使用Python开发中常用的模块之一,在使用过程中也会遇到很多问题,最重要的是把文档看明白并熟练掌握,在datetime模块中有以下几个类

目录


Python datetime模块之datetime

Python datetime 模块之timedelta

Python datetime模块之date

Python datetime模块之time


还有2个类,tzinfo、timezone。首先是我没明白这两个类是什么意思,其次,我不知道这个有什么用(废话,不知道什么意思,当然不知道用法了)。总而言之,是我愚钝。

tzinfo是一个抽象类,不能直接实例化,需要派生出一个子类。至少应该通过datetime的方法实现tzinfo中的方法,datetime模块中有一个tzinfo的派生类 timezone。
一个tzinfo的派生类可以在datetime和time的构造函数中。我 只理解这些,至于这个有什么用,我只知道是用于不同时区之间的时间偏移量和时区的相关方法。


以下是Python中时间的占位符表格:


符号英文含义中文含义例子%aWeekday as locale’s abbreviated name星期名称缩写Sun, Mon, ..., Sat (en_US);So, Mo, ..., Sa (de_DE)%AWeekday as locale’s full name星期名称全称Sunday, Monday, ..., Saturday (en_US);Sonntag, Montag, ..., Samstag (de_DE)%wWeekday as a decimal number, where 0 is Sunday and 6 is Saturday.星期的数字表示,0——60,1……6%dDay of the month as a zero-padded decimal number.日期的十进制表示01, 02, ..., 31%bMonth as locale’s abbreviated name.月份的简称Jan, Feb, ..., Dec (en_US);Jan, Feb, ..., Dez (de_DE)%BMonth as locale’s full name月份的全称January, February, ..., December (en_US);Januar, Februar, ..., Dezember (de_DE)%mMonth as a zero-padded decimal number.月份的十进制表示01, 02, ..., 12%yYear without century as a zero-padded decimal number.以0填充的十进制数表示的不带世纪的年份00, 01, ..., 99%YYear with century as a decimal number.以0填充的十进制数表示的带世纪的年份0001, 0002, ..., 2013, 2014, ..., 9998, 9999%HHour (24-hour clock) as a zero-padded decimal number.以0填充的24小时制表示小时00, 01, ..., 23%IHour (12-hour clock) as a zero-padded decimal number.以0填充的12小时制表示小时01, 02, ..., 12%pLocale’s equivalent of either AM or PM.AM或PM地域性设置

AM, PM (en_US);am, pm (de_DE)
%MMinute as a zero-padded decimal number.以0填充的十进制数表示分钟00, 01, ..., 59%SSecond as a zero-padded decimal number.以0填充的十进制数表示秒00, 01, ..., 59%fMicrosecond as a decimal number, zero-padded on the left.以0填充的十进制数表示微秒000000, 000001, ..., 999999%zUTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).+HHMM或-HHMM形式的UTC偏移(如果对象是naive的,则为空字符串)。(empty), +0000, -0400, +1030%ZTime zone name (empty string if the object is naive).时区名称(如果对象是naive的,则为空字符串)。(empty), UTC, EST, CST%jDay of the year as a zero-padded decimal number.以0填充的十进制数字表示的一年中的日期。001, 002, ..., 366%UWeek number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.以0填充的十进制数字表示的一年中的周。00, 01, ..., 53%WWeek number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.以0填充的十进制数字表示的一年中的周。00, 01, ..., 53%cLocale’s appropriate date and time representation.适合区域设置的日期和时间表示。Tue Aug 16 21:30:00 1988 (en_US);Di 16 Aug 21:30:00 1988 (de_DE)%xLocale’s appropriate date representation.适合区域的日期表示。08/16/88 (None);08/16/1988 (en_US);16.08.1988 (de_DE)%XLocale’s appropriate time representation.适合区域的日期表示。21:30:00 (en_US);21:30:00 (de_DE)%%A literal '%' character.%


以上文档来源于:https://python.freelycode.com/doc/python_3_5_0/library/datetime.html?highlight=datetime#datetime.tzinfo

如有出入,麻烦指出。谢谢


0 0
原创粉丝点击