Datetime,Python(20170204)

    xiaoxiao2021-03-26  19

    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 timedelta d = 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
    转载请注明原文地址: https://ju.6miu.com/read-658724.html

    最新回复(0)