datetime timestamp use

Coding = UTF-8 # 
Import Time 
Import datetime 

DEF yes_time (): 
    # get the current time 
    now_time datetime.datetime.now = () 
    # The current time minus one day yesterday to get the current time 
    yes_time = now_time + datetime.timedelta (days = -1 ) 
    # formatted output 
    yes_time_str yes_time.strftime = ( '% Y-M-% D%% H:% M:% S') 
    Print yes_time_str # 2017-11-01 22:56:02 

DEF dif_time (): 
    # calculation the time difference between two 
    now_time = datetime.datetime.now () 
    now_time now_time.strftime = ( '% Y-M-% D%% H:% M:% S') 
    D1 = datetime.datetime.strptime ( ' 19:21:22 2017-10-16 ','% Y-M-% D%% H:% M:% S ') 
    D2 = datetime.datetime.strptime (now_time,'% Y-M-% D% H%:% M:% S ') 
    # interval days 
    day = (d2 - d1).days 
    # seconds between 
    SECOND = (D2 - D1) .seconds 
    Print #. 17 Day 
    Print # 13475 SECOND attention to only the calculated number of seconds after the calculated amount h is the difference between the number of days not contain 

DEF unix_time (): 
    # The datetime converted to the python unix timestamp 
    DTIME = datetime.datetime.now () 
    un_time = time.mktime (dtime.timetuple ()) 
    Print un_time 1509636609.0 # 
    # unix timestamp to convert the python datetime 
    unix_ts = 1509636585.0 
    Times = datetime. datetime.fromtimestamp (unix_ts) 
    Print Times # 2017-11-02 23:29:45

Guess you like

Origin www.cnblogs.com/zhaohuanhuan/p/11230776.html