Python 我如何转换上午12点和下午12点的时间?

Python 我如何转换上午12点和下午12点的时间?,python,openerp,Python,Openerp,我想转换上午和下午的时间 这是我的代码: new_lead_time_schedule = datetime.strptime(sale_order_line.order_id.date_order, DEFAULT_SERVER_DATETIME_FORMAT) + timedelta(days=sale_order_line.customer_lead or 0.0) if sale_order_line.shift2 == 'morning'

我想转换上午和下午的时间

这是我的代码:

            new_lead_time_schedule = datetime.strptime(sale_order_line.order_id.date_order, DEFAULT_SERVER_DATETIME_FORMAT) + timedelta(days=sale_order_line.customer_lead or 0.0)
            if sale_order_line.shift2 == 'morning':
                new_lead_time_schedule = fields.Datetime.context_timestamp(self, new_lead_time_schedule).replace(hour=0, minute=0, second=0).astimezone(utc)
            elif sale_order_line.shift2 == 'afternoon':
                new_lead_time_schedule = fields.Datetime.context_timestamp(self, new_lead_time_schedule).replace(hour=4, minute=0, second=0).astimezone(utc)

但在我的数据未更改的情况下,如何转换时间AM和PM?

您好,您可以尝试以下过程:

翻译-->语言-->编辑

将时间格式:%H:%M:%S替换为%I:%M:%S%p

导入以下内容:

从odoo.tools导入float\u为0,float\u比较,默认\u服务器\u日期时间\u格式

在函数中定义替代时间格式的默认服务器日期时间格式 我希望它能帮助你