擅长:python、mysql、java
<p>我不太熟悉EDT时区,但这个例子应该符合您的目的。</p>
<pre><code>import datetime
</code></pre>
<p>必须向datetime.datetime.now传递时区信息,该信息应为datetime.tzinfo类型。这里有一个类,它用一些必需的函数实现了这个功能。我在这里没有提供日光节约的细节,因为这是一个例子。</p>
<pre><code>class EST(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=-5)
def dst(self, dt):
return datetime.timedelta(0)
</code></pre>
<p>现在你可以用这个来获得时区正确的信息:</p>
<pre><code>print datetime.datetime.now(EST())
</code></pre>
<p>输出:</p>
<pre><code>2010-11-01 13:44:20.231259-05:00
</code></pre>