为什么Python将我的默认时区设置为-1?

时间:2010-10-15 08:46:59

标签: python sqlite timezone

我使用Python来跟踪本地SQLite和远程网页之间的版本。通过HTTP响应中的Last-modified和文件大小信息来比较它们很有用。我在开发过程中发现了一些有趣的东西。

def time_match(web,sql):
  print web,sql
  t1 = time.strptime(web,"%a, %d %b %Y %H:%M:%S %Z")
  t2 = time.strptime(sql,"%Y-%m-%d %H:%M:%S")
  print t1,t2
  if t1==t2:
    print "same time"
  else:
    print "different time"
  return t1==t2

在上面的代码中,我尝试将从Web和SQLite的时间解码为内部时间并进行比较。让我们看一下打印屏幕如下:

Wed, 13 Oct 2010 01:13:26 GMT 2010-10-13 01:13:26
(2010, 10, 13, 1, 13, 26, 2, 286, 0) (2010, 10, 13, 1, 13, 26, 2, 286, -1)
different time

结果显示GMT被正确解码,而Python的默认时区日期时间似乎为-1。我的系统时区实际上是+8,-1来自哪里? SQLite的?

1 个答案:

答案 0 :(得分:1)

-1对象中最后一个位置的time.struct_time并不意味着您处于'UTC-01:00'。它表示未定义的属性is_dst(因为YYYY-MM-DD HH:MM:SS格式不包含有关当前时区或夏令时模式的任何信息。)

time.strptime('2010-10-15 11:01:02', '%Y-%m-%d %H:%M:%S')
# returns the following on a computer with Central European Sommer Time (CEST, +02:00):
time.struct_time(tm_year=2010, tm_mon=10, tm_mday=15, tm_hour=11, tm_min=1, tm_sec=2, tm_wday=4, tm_yday=288, tm_isdst=-1)