def chinese_time(timestamp, all_time=True):
    leap_month = ''
    if lunardate.LunarDate.fromSolarDate(timestamp.year, timestamp.month,
                                         timestamp.day).isLeapMonth:
        leap_month = '闰'
    if all_time:
        return str(timestamp.year) + '年' + str(timestamp.month) + '月' + str(
            timestamp.day) + '日' + '(阴历' + pycnnum.num2cn(
                lunardate.LunarDate.fromSolarDate(
                    timestamp.year, timestamp.month,
                    timestamp.day).month) + leap_month + '月' + pycnnum.num2cn(
                        lunardate.LunarDate.fromSolarDate(
                            timestamp.year, timestamp.month,
                            timestamp.day).day) + ')' + str(
                                timestamp.hour) + '时'
    else:
        return str(timestamp.month) + '月' + str(
            timestamp.day) + '日' + '(阴历' + pycnnum.num2cn(
                lunardate.LunarDate.fromSolarDate(
                    timestamp.year, timestamp.month,
                    timestamp.day).month) + leap_month + '月' + pycnnum.num2cn(
                        lunardate.LunarDate.fromSolarDate(
                            timestamp.year, timestamp.month,
                            timestamp.day).day) + ')' + str(
                                timestamp.hour) + '时'
Пример #2
0
def solar2lunar_d(d):
    # 将阳历转化为阴历
    # 汉字格式改写
    han_zi = pycnnum.num2cn(lunardate.LunarDate.fromSolarDate(d.year, d.month, d.day).day)
    han_zi = han_zi.replace('一十', '十')
    m =  pycnnum.num2cn(lunardate.LunarDate.fromSolarDate(d.year, d.month, d.day).month)
    m = m.replace("一十一","冬").replace("一十二","腊").replace("一十",'十') + "月"
    if len(m) == 1:
        if m == "一":
            m = "正"
    if len(han_zi) == 3:
        han_zi =  han_zi.replace('二十', '廿')
    if len(han_zi) == 1:
        han_zi = '初' + han_zi
    return m + han_zi
 def solar2lunar_d(self, d):
     #将阳历转化为阴历
     #汉字格式改写
     han_zi = pycnnum.num2cn(
         lunardate.LunarDate.fromSolarDate(d.year, d.month, d.day).day)
     han_zi = han_zi.replace('一十', '十')
     if len(han_zi) == 3:
         return han_zi.replace('二十', '廿')
     if len(han_zi) == 1:
         return '初' + han_zi
     else:
         return han_zi
Пример #4
0
def near_years(years):
    near_year_list = []
    for year in years:
        x0 = 2018 - int(year)
        x = str(x0)
        if x == '0' or x0 == 0:
            y = '今年'
            y0 = y
        else:
            y = '近' + x + '年'
            cn_digital = num2cn(x0, numbering_type='low', alt_two=True, use_zeros=True, big=False, traditional=False)
            y0 = '近' + cn_digital + '年'
        near_year_list.append(y)
        near_year_list.append(y0)
    near_year_list.append('近两年')
    return near_year_list