码迷,mamicode.com
首页 > 其他好文 > 详细

PyPI - Datetime

时间:2019-02-17 14:18:26      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:new   struct   ret   values   set   bit   head   other   timezone   

PyPI for Python 3.7

import datetime

https://docs.python.org/3.7/library/datetime.html

timedelta Object

https://docs.python.org/3.7/library/datetime.html#timedelta-objects

Constructor:

datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

It also has a lot of operations. See the Documents for detail.

date Object

https://docs.python.org/3.7/library/datetime.html#date-objects

Datetime object is a combination of a date and a time. I like to use datetime object instead.

datetime Object

https://docs.python.org/3.7/library/datetime.html#datetime-objects

Constructor:

  • datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
  • datetime.datetime.fromtimestamp(timestamp, tz=None),By timestamp
  • datetime.datetime.combine(date, time, tzinfo),Combine date object and time object
  • datetime.datetime.strptime(date_string, format),By string and format

Ordinal Date is the proleptic Gregorian ordinal of the date. It is the count from 0001-01-01, just like timestamp.

Instance methods:

(Notice: a is the name of a exist datetime object)

  • a.replace(), Return a datetime with the same attributes, except for those attributes given new values.
  • a.astimezone(), Return a datetime object with the timezone you give.
  • a.timetuple(), Return a tuple. You can pick up what you need by index or others.
  • a.toordinal(), Return the ordinal.
  • a.timestamp(), Return the timestamp.
  • a.strftime(format), Return the format string.

timezone Object

https://docs.python.org/3.7/library/datetime.html#timezone-objects

  • datetime.timezone(offset), The offset attribute must be timedelta.

String format:

(strftime --> string from time. strptime())

https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior

Directive Tips Meaning Example
%Y Year 4 bits Year 0001, 0002,..., 2019
%m Month 1/2 bits Month 01, 02, ..., 12
%d Day 1/2 bits Day 01, 02, ..., 31
%H Hour 2 bits Hour 00, 01, ..., 23
%M Minute 2 bits Minute 00, 01, ..., 59
%S Second 2 bits Second 00, 01, ..., 59
%w Week 1 bit, 0 for Sun. and 6 is Sat. 0, 1, ..., 6

PyPI - Datetime

标签:new   struct   ret   values   set   bit   head   other   timezone   

原文地址:https://www.cnblogs.com/kaimobile/p/10390967.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!