美文网首页
时间戳、字符串转换

时间戳、字符串转换

作者: ckawyh | 来源:发表于2019-03-18 17:24 被阅读0次
    # 时间戳转日期
    def process_time(row):
        timeStamp = row['sort'][0]/1000
        date_array = time.localtime(timestamp)
        date_str = time.strftime("%Y-%m-%d %H:%M:%S", date_array)
        return date_str
      
    df_origin['time'] = df_origin.apply(process_time, axis=1)
    
    # 字符串转时间戳
    start_time_str = "2018-12-30 00:00:00"
    end_time_str = "2018-12-31 23:59:59"
    
    def timeStr2Stamp(time_str):
        time_dt = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S")
        timestamp = int(time.mktime(time_dt.timetuple())) * 1000
        return timestamp
    
    start_timestamp = timeStr2Stamp(start_time_str)
    print('start_timestamp:', start_timestamp)
    end_timestamp = timeStr2Stamp(end_time_str)
    print('end_timestamp:', end_timestamp)
    

    相关文章

      网友评论

          本文标题:时间戳、字符串转换

          本文链接:https://www.haomeiwen.com/subject/dxybmqtx.html