crac

导航

get_time

def get_current_time():
    #将python的datetime转换为unix时间戳
    dtime = datetime.datetime.now()
    un_time = time.mktime(dtime.timetuple())
    #print un_time  #1509636609.0
    #将unix时间戳转换为python  的datetime
    unix_ts = un_time
    times = datetime.datetime.fromtimestamp(unix_ts)
    #print times
    return times  #2017-11-02 23:29:45

 

posted on 2018-06-26 20:36  crac  阅读(109)  评论(0编辑  收藏  举报