PyPI - Datetime
PyPI for Python 3.7
import datetime
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 timestampdatetime.datetime.combine(date, time, tzinfo)
,Combine date object and time objectdatetime.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 |
最新文章
- Computer Vision: OpenCV, Feature Tracking, and Beyond--From <;<;Make Things See>;>; by Greg
- 非递归创建二叉树( C++队列 )
- python3.x + selenium 3.x 遇到的问题:Exception ignored in: <;bound method Service.__del__ of <;selenium.webdriver.firefox.service.Service object at 0x0045E450>;>;
- JNI笔记
- [WinAPI] API 3 [获取系统目录,并保存在文件里]
- ”靠谱的C#“单例模式
- editPlus,3.7V 注册码
- (转)Android L Ripple的使用
- .net导出Word的一种方法
- c语言学习之基础知识点介绍(二十):预处理指令
- EmitMapper 和TinyMapper 两者简单对比
- QQ_MultiTalkServer
- [leetcode-565-Array Nesting]
- Git 初体验
- mySQL简单操作(三)
- js 返回小数点后几位
- CRM系统(第一部分)
- flask下载文件中文IE,Edge,Safari文件名乱码
- Amaze UI 云适配
- Spark实践 -- 性能优化基础
热门文章
- MySQL创建用户的三种方法
- Python学习---递归函数的学习
- Long Wei information technology development Limited by Share Ltd interview summary.
- WBS 工作分解结构
- January 26 2017 Week 4 Thursday
- 使用C#检验.NET FrameWork版本
- Core Animation 与 GPU
- HDU 6464 免费送气球 【权值线段树】(广东工业大学第十四届程序设计竞赛)
- Linux 进程与信号的概念和操作 linux process and signals
- 【luogu P2279 [HNOI2003]消防局的设立】 题解