首页 > 学院 > 开发设计 > 正文

Datetime,Python(2017/02/04)

2019-11-14 09:25:35
字体:
来源:转载
供稿:网友

References 1. Python for Data analysis 2. Useful Links https://docs.python.org/2/library/datetime.html

Step1: import packages from library

from datetime import datetime, date, time,timedelta

Background information,

date: contain attributes like year, month, day time: contain attributes like hour, minute, second, microsecond and tzinfo datetime: a combination of date and time, PRovide attributes year, month, day, hour, minute, second, microsecond, and tzinfo. timedelta: represents a duration, the difference between two dates or times.

from datetime import timedeltad = timedelta(microseconds=-1)(d.days, d.seconds, d.microseconds)

Step2: application of datetime

create user-written datetime

dt = datetime(2017,02,04,15,05,55) –> 2017/02/04 15:05:55

manipulation of datetime add 1 day to ‘dt’ dt2 = dt + timedelta(second = 86400) –> 2017/02/05 15:05:55 the difference between two dates (dt2 - dt).total_seconds()—> Return the total number of seconds contained in the duration
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表