四柱排盘系统--阳历转农历

用QT实现阳历转换农历的功能

使用工具

QT Creator
C++

描述:

本功能是根据输入的阳历信息,转换成对应的农历信息。

关键点:

1:选择时间,23点之前为当天,23点之后为第二天。
2:如果为第二天,那么要考虑,月份要不要加1,年份要不要加1。
3:这里注意,年份为六十甲子循环,没有数字的标识,也就是说,1900年为庚子年,那么2020年也为庚子年,名称上没有区别。
4:计算当年是否有闰月,有的话,是闰几月,闰月是多少天?

运行效果如下:

代码下载:

https://download.csdn.net/download/leoeitail/20417579?spm=1001.2014.3001.5501

代码展示:

nongli.h

#ifndef NONGLI_H
#define NONGLI_H

// 阳历1900.1.1
// 在阳历为1900.1.31 时阴历为1900.1.1 即1900年正月初一

class nongli
{
public:
    ///初始化年月日数据
    void Init();

    //确定是否存在农历的闰月 并返回闰月
    unsigned char get_leap_month(unsigned int lunar_year)
    {
        return lunar_info[lunar_year-1900]&0xf;
    }

    //若存在闰月,返回闰月的天数,30?29
    unsigned char get_leap_month_day(unsigned int lunar_year)
    {
        if(get_leap_month(lunar_year))
            return( ( (lunar_info[lunar_year-1900]) & 0x10000 ) ? 30:29 );

        return(0);
    }

    //确定农历当月天数,30?29
    unsigned char get_lunar_month_total(unsigned int lunar_year, unsigned char lunar_month)
    {
        return( (lunar_info[lunar_year-1900] & (0x10000>>lunar_month) ) ? 30:29 );
    }

    // 农历当年总天数,354?355 384 383
    unsigned int get_lunar_year_total(unsigned int lunar_year)
    {
        //12个月 29天一月
        unsigned int sum = 348;
        unsigned int i;
        for(i=0x8000; i>0x8; i>>=1)
            sum += (lunar_info[lunar_year-1900]&i) ? 1 : 0; //把大月的1加进去
        return(sum+get_leap_month_day(lunar_year)); //判断这年是否有闰月
    }

    //判断是否为闰年
    unsigned int leap(unsigned int year)
    {
        if( (year%4==0 &&year%100!=0) || year%400==0 )
            return 366;

        return 365;
    }

    //判断当年当月天数
    unsigned char day(unsigned int year ,unsigned char month)
    {
        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
            return 31;
        if(month==4||month==6||month==9||month==11)
            return 30;
        if(month==2&&leap(year)==366)
            return 29;
        else
            return 28;
    }

    //计算1900.1.1 到 输入年月的天数
    unsigned int get_solar_total(unsigned int solar_year, unsigned char solar_month)
    {
        unsigned int total;
        unsigned int temp_num;
        total=0;
        for(temp_num=190
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三月桃花浪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值