<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[odoo 8 11   导出excel，时间类型字段 时区问题解决]]></title><description><![CDATA[<p dir="auto"><a href="https://github.com/gilbert-yuan/odoo_config" rel="nofollow ugc">https://github.com/gilbert-yuan/odoo_config</a></p>
<pre><code>from openerp.fields import Datetime, Field
ISODATEFORMAT = '%Y-%m-%d'

Newdatetime = Datetime.convert_to_export
def convert_to_export(self, value, env):
   timezone = pytz.timezone(env.context.get('tz'))
   return_val = Newdatetime(self, value, env)
   if isinstance(return_val, datetime.datetime) and return_val:
       return self.to_string(return_val.replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone))
   elif return_val:
       return self.to_string(self.from_string(return_val).replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone))
   return return_val
Datetime.convert_to_export = convert_to_export


import datetime, pytz
from odoo.fields import Datetime

Newdatetime = Datetime.convert_to_export


def convert_to_export(self, value, record):
 timezone = pytz.timezone(record._context.get('tz'))
 return_val = Newdatetime(self, value, record)
 if isinstance(return_val, datetime.datetime) and return_val:
     return self.to_string(return_val.replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone))
 elif return_val:
      return self.to_string(self.from_string(return_val).replace(tzinfo=pytz.timezone('UTC')).astimezone(timezone))
return return_val
Datetime.convert_to_export = convert_to_export
</code></pre>
]]></description><link>https://odoo.net.cn/topic/4977/odoo-8-11-导出excel-时间类型字段-时区问题解决</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 20:47:48 GMT</lastBuildDate><atom:link href="https://odoo.net.cn/topic/4977.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Apr 2018 06:54:07 GMT</pubDate><ttl>60</ttl></channel></rss>