可以使用Python内置的datetime模块来将时间格式转换为数字。具体步骤如下:

3. 将datetime对象转换为时间戳
其中,`strptime()`方法用于将时间字符串转换为datetime对象,第一个参数为时间字符串,第二个参数为时间字符串的格式。`timestamp()`方法用于将datetime对象转换为时间戳,即秒数。
即2022年1月1日12点的时间戳。
Python中的时间转换需要提供自己的tzinfo类,tzinfo类在Python中用来描述时区信息,tzinfo在Python中是抽象类,因此必须要自己写tzinfo的子类;在中国使用的时间是GMT+8,也就是中国的时间会比GMT时间快8小时:from datetime import datetime,timedelta,tzinfoclass GMT8(tzinfo): delta=timedelta(hours=8) def utcoffset(self,dt): return self.delta def tzname(self,dt): return "GMT+8" def dst(self,dt): return self.deltaclass GMT(tzinfo): delta=timedelta(0) def utcoffset(self,dt): return self.delta def tzname(self,dt): return "GMT+0" def dst(self,dt): return self.delta from_tzinfo=GMT()#格林威治时区,0时区local_tzinfo=GMT8()#本地时区,+8区gmt_time = datetime.strptime('2011-08-15 21:17:14', '%Y-%m-%d %H:%M:%S')gmt_time = gmt_time.replace(tzinfo=from_tzinfo)local_time = gmt_time.astimezone(local_tzinfo)如果你不想自己写tzinfo的具体子类,可以使用pytz:
http://pypi.python.org/pypi/pytz/