python之模块datetime详解

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python之模块datetime详解 import datetime
#data=datetime.date(2015,11,9)#表示日期的类
#data=datetime.time(hour[,minute[,second[,microsecond[,tzinfo]]]])#表示时间的类,从小时时间开始为参数
#data=datetime.datetime(year,month,day[,hour[,minute[,second[,microsecond[,tzinfo]]]]])#表示日期时间,其实就是前面2个综合
#data=datetime.timedelta()#表示时间间隔,即两个时间点之间的长度
#data=datetime.tzinfo()#与时区有关的相关信息 '''
>>> help(datetime)
CLASSES
__builtin__.object
date
datetime
time
timedelta
tzinfo class date(__builtin__.object)
| date(year, month, day) --> date object
| #得到一个日期对象,需传递3个参数
#data=datetime.date(2015,11,8)#2015-11-08 | Methods defined here:
| ctime(...) #返回一个时间风格的字符串
#data.ctime()#Sun Nov 8 00:00:00 2015 | Return ctime() style string.
|
| fromordinal(...) #将Gregorian日历时间转换为date对象,西方国家使用比较多,此处不详细展开讨论
#了解即可
| int -> date corresponding to a proleptic Gregorian ordinal.
|
| fromtimestamp(...) #根据给定的时间戮,返回一个date对象
#data.fromtimestamp(1111111111)#2005-03-18
| timestamp -> local date from a POSIX timestamp (like time.time()).
|
| isocalendar(...)
#data.isocalendar()#(2015, 45, 7),
#注意:返回的年、月、日的元组,返回结果有问题,45个月???
| Return a 3-tuple containing ISO year, week number, and weekday.
|
| isoformat(...)
#data.isoformat()#2015-11-08
#返回格式如'YYYY-MM-DD'的字符串
| Return string in ISO 8601 format, YYYY-MM-DD.
|
| isoweekday(...)
#data.isoweekday()#1
#返回当前的星期数,如今天星期一,则返回数值1,如为星期天,则返回7 | Return the day of the week represented by the date.
| Monday == 1 ... Sunday == 7
|
| replace(...)
#data.replace(2014,8,01)#2014-08-01
#相当于string的replace替换功能,如果不写参数则默认不做替换处理 | Return date with new specified fields.
|
| strftime(...)
#data.strftime('%Y-%m-%d %H-%M-%S')#2015-11-09 00-00-00
#按照自定义风格来格式化时间字符串
| format -> strftime() style string.
|
| timetuple(...)
#返回time.struct_time对象
#data.timetuple()#time.struct_time(tm_year=2015, tm_mon=11, tm_mday=9, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=313, tm_isdst=-1) | Return time tuple, compatible with time.localtime().
|
| today(...)
#data.today()#2015-11-09
#返回一个表示当前本地时间的datetime对象
| Current date or datetime: same as self.__class__.fromtimestamp(time.time()).
|
| toordinal(...)
#返回日期对应的Gregorian Calendar日期.
#了解即可
| Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
|
| weekday(...)
#返回weekday,
#如果是星期一,返回0,如果是星期2,返回1,以此类推.
| Return the day of the week represented by the date.
| Monday == 0 ... Sunday == 6
|
| ----------------------------------------------------------------------
| Data descriptors defined here:#数据描述符定义在这里
|
| day
|
| month
|
| year
| ----------------------------------------------------------------------
class datetime(date)
| datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
|
| The year, month and day arguments are required. tzinfo may be None, or an
| instance of a tzinfo subclass. The remaining arguments may be ints or longs. | Methods defined here:
| astimezone(...)
#data.astimezone()#根据给定的timezone对象,返回转换为本地时区的timezone对象
#了解有这么个东西即可
| tz -> convert to local time in new timezone tz
|
| combine(...)##不做了解 | date, time -> datetime with same date and time fields
|
| ctime(...)
#data.ctime()#Mon Nov 9 00:26:10 2015 | Return ctime() style string.
|
| date(...)
#data.date()#2015-11-09
#返回日期时间对象中的日期信息
| Return date object with same year, month and day.
|
| dst(...)#不做了解 | Return self.tzinfo.dst(self).
|
| fromtimestamp(...)
#datetime.fromtimestamp(timestamp[, tz]):
#根据时间戮创建一个datetime对象,参数tz指定时区信息;
#data.fromtimestamp(1111111111)#2005-03-18 09:58:31
| timestamp[, tz] -> tz's local time from POSIX timestamp.
|
| isoformat(...)
#data.isoformat()#2015-11-09T00:26:10
#了解即可
| [sep] -> string in ISO 8601 format, YYYY-MM-DDTHH:MM:SS[.mmmmmm][+HH:MM].
|
| sep is used to separate the year from the time, and defaults to 'T'.
|
| now(...)
#data.now()#2015-11-09 00:39:43.894000
#现在的日期时间
| [tz] -> new datetime with tz's local day and time.
|
| replace(...)
#data.replace(2005,11,9,00,26,10)#2005-11-09 00:26:10
#可以不传参
#相当于string的替换方法
| Return datetime with new specified fields.
|
| strptime(...)
#参数:
#format:格式化,如:%Y-%m-%d %H:%M:%S
#string:时间字符串,如:2012-03-05 16:26:23
#data.strptime('2012-03-05 16:26:23','%Y-%m-%d %H:%M:%S')#2012-03-05 16:26:23
#返回:日期时间
| string, format -> new datetime parsed from a string (like time.strptime()).
|
| time(...)
#data.time()#00:26:10
#返回日期时间中的时间,其实就是从日期时间中把时间分离出来 | Return time object with same time but with tzinfo=None.
|
| timetuple(...)
#data.timetuple()#time.struct_time(tm_year=2015, tm_mon=11, tm_mday=9, tm_hour=0, tm_min=26, tm_sec=10, tm_wday=0, tm_yday=313, tm_isdst=-1)
#返回:time.struct_time对象
#做了解即可,一般用的比较少
| Return time tuple, compatible with time.localtime().
|
| timetz(...)
#data.timetz()#00:26:10
#返回时间对象
| Return time object with same time and tzinfo.
|
| tzname(...)#不做了解
| Return self.tzinfo.tzname(self).
|
| utcfromtimestamp(...)#不做了解
| timestamp -> UTC datetime from a POSIX timestamp (like time.time()).
|
| utcnow(...)
#data.utcnow()#2015-11-08 16:48:29.194000
#返回一个当前utc时间的datetime对象
| Return a new datetime representing UTC day and time.
|
| utcoffset(...)#不做了解
| Return self.tzinfo.utcoffset(self).
|
| utctimetuple(...)#不做了解
| Return UTC time tuple, compatible with time.localtime().
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| hour
| microsecond#微秒
| minute
| second#秒
| tzinfo
| class time(__builtin__.object)
| time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object
|
| All arguments are optional. tzinfo may be None, or an instance of
| a tzinfo subclass. The remaining arguments may be ints or longs.
|
| Methods defined here:
| dst(...)
| Return self.tzinfo.dst(self).
|
| isoformat(...)
#data.isoformat()#00:26:10
#返回型如"HH:MM:SS"格式的字符串表示
| Return string in ISO 8601 format, HH:MM:SS[.mmmmmm][+HH:MM].
|
| replace(...)
| Return time with new specified fields.
|
| strftime(...)
#data.strftime('%H-%M-%S')#00-26-10
#返回自定义格式化字符串
| format -> strftime() style string.
|
| tzname(...)#不做了解
| Return self.tzinfo.tzname(self).
|
| utcoffset(...)#不做了解
| Return self.tzinfo.utcoffset(self).
| ----------------------------------------------------------------------
class timedelta(__builtin__.object)
#timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
#注意timedelta的参数顺序
| Difference between two datetime values.
|
| Methods defined here:
|
| total_seconds(...)
#总持续秒数。
data.total_seconds()#86400.0
| Total seconds in the duration.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| days:Number of days.
|
| microseconds:Number of microseconds (>= 0 and less than 1 second).
|
| seconds:Number of seconds (>= 0 and less than 1 day).
| ----------------------------------------------------------------------
class tzinfo(__builtin__.object)
#tzinfo = UTC(8)----东8区北京时间
#tzinfo类下的方法暂时不做了解.
| Abstract base class for time zone info objects.
|
| Methods defined here:
|
| dst(...)
| datetime -> DST offset in minutes east of UTC.
|
| fromutc(...)
| datetime in UTC -> datetime in local time.
|
| tzname(...)
| datetime -> string name of time zone.
|
| utcoffset(...)
| datetime -> minutes east of UTC (negative for west of UTC).
|
| ---------------------------------------------------------------------- DATA
MAXYEAR = 9999
MINYEAR = 1
datetime_CAPI = <capsule object "datetime.datetime_CAPI">
'''
上一篇:MySQL程序之mysqldump详解


下一篇:创建虚拟机、安装centos系统,xshell连接虚拟机