将datetime转换为POSIX时间 [英] Converting datetime to POSIX time

查看:78
本文介绍了将datetime转换为POSIX时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中将datetime或date对象转换为POSIX时间戳?有一些方法可以根据时间戳创建日期时间对象,但是我似乎没有找到任何明显的方法来执行相反的操作.

How do I convert a datetime or date object into a POSIX timestamp in python? There are methods to create a datetime object out of a timestamp, but I don't seem to find any obvious ways to do the operation the opposite way.

推荐答案

import time, datetime

d = datetime.datetime.now()
print time.mktime(d.timetuple())

这篇关于将datetime转换为POSIX时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆