如何从odoo 8中的月份号获取月份名称

时间:2017-05-22 09:57:05

标签: python-2.7

def generate_leave(self, cr, uid,ids, fields, context=None):
        if context is None:
            context = {}
        month_split = self.browse( cr, uid,ids)
        print "\n\n\n\n\n\n DATEE",month_split.name 
        dt =  datetime.strptime(month_split.name, "%Y-%m-%d")   
        year = dt.year
        print "\n\n\n\n YER",year
        month = dt.month
        print "\n\n\n MNTH",month
        currentMonth = datetime.now().month
        print "\n\n\n\n\n CURR MNTH",currentMonth
        date = dt.day
        print "\n\n\n\n\n\n DATTE",date
        day = dt.day
        print "\n\n\n\n\n\n DAYY",day

我试过这个但是我无法实现它。我使用了像“%b”和“%B”但没有任何作用。

1 个答案:

答案 0 :(得分:1)

请参阅http://docs.python.org/2/library/calendar.html

上的文档
import calendar

month_name= calendar.month_name[3]

print month_name

这对我来说很有效。这将返回" March"

在您的情况下,您应该像这样使用

month_name= calendar.month_name[dt.month]