Python 时间戳转换为字符串&字符串转换为时间戳

Python 时间戳转换为字符串&字符串转换为时间戳if name main 时间戳 importtimese time time 时间戳转换为字符串 print time strftime Y m d H M S time localtime seconds 字符串转换为时间戳 print time mktime time strptime 2018 08 07 Y m d

if __name__ == '__main__': # 时间戳 import time seconds = time.time() # 时间戳转换为字符串 print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(seconds))) # 字符串转换为时间戳 print(time.mktime(time.strptime("2018-08-07", "%Y-%m-%d")))
 if len(df) > 0: # 字符串转换为时间戳 x = list(df['日期']) x1 = [time.mktime(time.strptime(c, "%Y-%m-%d")) for c in x] df['日期时间戳'] = x1 df.sort_values(by='日期时间戳', inplace=True, ascending=True) 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/205721.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 下午5:21
下一篇 2026年3月19日 下午5:22


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号