精华内容
下载资源
问答
  • 微软专为中国用户定制的带农历系统日历
  • 带有农历日历

    2012-01-31 10:55:50
    日历 带有农历,节气和休息日,一共两个文件,html和js。
  • 该案例是实现了一款很不错的带有农历日历控件源码,该源码简单易懂,而且也容易上手,案例可以实现显示阳历和阴历,显示范围是1900年到2100年。左右滑动手势切换月份,标题点击出现年份和月份选择器,“今天”按钮...
  • 带农历日历

    2014-11-06 17:30:21
    这就是一个带农历日历文件,只有当前月份的,注释已经写好了,可以根据个人需要进行修改,哪里错,请提出,我会尽快修改
  • 带有农历的JC日历

    2008-04-12 20:14:28
    利用JCalendar,增加了一个中国农历的部分;不过在ff显示还有点问题
  • VC 支持时间日期的万年历 带农历日历,有人说这只是一个时钟,不过我觉得功能已远远超出时钟了,有日历可供查询,而且还带有农历,还有定时关机和定时提醒功能,还可以使用热键操作窗口的隐藏与显示,如果喜欢学习的...
  • 带农历的小日历插件

    2013-01-21 16:31:13
    一个黄道吉日的很方便、很简单的、很全面的带农历的小日历小插件
  • vue —— 带农历日历功能

    千次阅读 2019-02-20 14:24:59
    之前个项目需要自己写一个月份选择器,由此想起来做一个简单的日历,做起来一些自己感兴趣的东西,也为了记录一下,发个帖 首先,我做的日历是没有农历的,因为我不知道农历的历法是怎么计算的,从网上找了一个...

    闲来无事做一些简单功能,一边练习VUE的使用,一边锻炼逻辑思维能力。之前有个项目需要自己写一个月份选择器,由此想起来做一个简单的日历,做起来有一些自己感兴趣的东西,也为了记录一下,发个帖

    首先,我做的日历是没有农历的,因为我不知道农历的历法是怎么计算的,从网上找了一个似乎是很多年前的代码,功能不错,代码太乱就自己整理了一下,当然这段代码还是归写代码的大神所有,跟我没啥关系,特此声明

    1、分享代码

    Html代码

    <template>
      <div class="main">
        <div class="choose_year">
          <div class="icon" @click="chooseYears(-1)"><i class="fa fa-angle-double-left"></i></div>
          <div class="icon" @click="chooseMonth(-1)"><i class="fa fa-angle-left"></i></div>
          <div class="date">{{year}}.{{month.toString().padStart(2, '0')}}</div>
          <div class="icon" @click="chooseMonth(1)"><i class="fa fa-angle-right"></i></div>
          <div class="icon" @click="chooseYears(1)"><i class="fa fa-angle-double-right"></i></div>
        </div>
        <div class="days_area">
          <div class="day week" v-for="week in weeks" :key="week">{{week}}</div>
          <div class="day" @click="chooseThisDay(day.gregorian)" v-for="(day, index) in days" :key="index" :class="day.gregorian === today ? 'choose_day' : ''">
            <p>{{day.gregorian}}</p>
            <span>{{day.lunar}}</span>
          </div>
        </div>
      </div>
    </template>

    SCSS代码

    <style lang="scss" scoped>
      .main{
        .choose_year{
          display: flex;
          .icon{
            width: 10%;
            height: 8vh;
            line-height: 8vh;
            text-align: center;
          }
          .date{
            width: 60%;
            text-align: center;
            height: 8vh;
            line-height: 8vh;
            font-size: 1.2rem;
          }
        }
        .days_area{
          display: flex;
          flex-wrap: wrap;
          .day{
            width: 14.28%;
            text-align: center;
            padding: 1vh 0;
            margin-top: 1vh;
            p{
              margin: 0;
              font-size: 6vw;
            }
            span{
              font-size: 3vw;
            }
          }
          .week{
            background-color: dodgerblue;
            color: #fff;
            font-weight: bold;
            height: 6vh;
            line-height: 4vh;
            margin: 0;
          }
          .choose_day{
            background-color: dodgerblue;
            color: #fff;
            font-weight: bold;
          }
        }
      }
    </style>

    效果图

     

    当然效果很一般啦,如果你要这种日历的话,自己精心调校一下样式应该...也比我好不到哪里去吧,哈哈哈哈

    JS代码

    export default {
      name: 'calendar',
      data () {
        return {
          year: 0,
          month: 0,
          today: 0,
          days: [],
          weeks: ['一', '二', '三', '四', '五', '六', '日']
        }
      },
      mounted () {
        const now = new Date()
        this.year = now.getFullYear()
        this.month = now.getMonth() + 1
        this.today = now.getDate()
        this.getDays()
      },
      methods: {
        getDays () { // 获取当前月份所有公历日期及其农历日期
          this.days = []
          const day = new Date()
          day.setFullYear(this.year, this.month - 1, 1) // 此处较之前调整,获取当月第一天
          const month = new Date()
          month.setFullYear(this.year, this.month, 0) // 此处较之前调整,获取当月
          for (let i = 1; i < day.getDay(); i++) { // 当月第一天距离所在周周一的空白占位
            this.days.push({ gregorian: '', lunar: '' })
          }
          for (let i = 1; i <= month.getDate(); i++) { // 获取当月天数填充日历
            this.days.push({ gregorian: i, lunar: this.getLunarDay(this.year, this.month, i) })
          }
        },
        chooseYears (state) { // 改变年份
          this.year += state
          this.today = 1
          this.getDays()
        },
        chooseMonth (state) { // 改变月份
          this.month += state
          this.today = 1
          if (this.month < 1) {
            this.month = 12
            this.chooseYears(-1)
          } else if (this.month > 12) {
            this.month = 1
            this.chooseYears(1)
          } else {
            this.getDays()
          }
        },
        chooseThisDay (day) { // 选择某天,主要是考虑可以当时间选择器用
          if (day > 0) {
            this.today = day
          }
        },
        getLunarDay (solarYear, solarMonth, solarDay) { // 拷贝别人又自己调整过的获取农历日期的代码,想要原来的代码估计百度一下就有了
          const madd = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
          // const tgString = '甲乙丙丁戊己庚辛壬癸'
          // const dzString = '子丑寅卯辰巳午未申酉戌亥'
          const numString = '一二三四五六七八九十'
          const monString = '正二三四五六七八九十冬腊'
          const CalendarData = [0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6, 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD, 0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B, 0x25D, 0x92D, 0x2192B, 0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6, 0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, 0x612DA, 0x95B, 0x49B, 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497, 0x64B, 0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95]
          if (!(solarYear < 1921 || solarYear > 2999)) { // 注意看此处限定了年份,设置自己需要的范围即可
            solarMonth = (parseInt(solarMonth) > 0) ? (solarMonth - 1) : 11
            const timeArr = [solarYear, solarMonth, solarDay]
            let TheDate = (timeArr.length !== 3) ? new Date() : new Date(timeArr[0], timeArr[1], timeArr[2])
            let total, m, n, k
            let isEnd = false
            let theDateYear = TheDate.getFullYear()
            total = (theDateYear - 1921) * 365 + Math.floor((theDateYear - 1921) / 4) + madd[TheDate.getMonth()] + TheDate.getDate() - 38
            if (theDateYear % 4 === 0 && TheDate.getMonth() > 1) {
              total++
            }
            for (m = 0; ; m++) {
              k = (CalendarData[m] < 0xfff) ? 11 : 12
              for (n = k; n >= 0; n--) {
                if (total <= this.getBit(CalendarData[m], n)) {
                  isEnd = true
                  break
                }
                total = total - this.getBit(CalendarData[m], n)
              }
              if (isEnd) {
                break
              }
            }
            let cMonth, cDay // cYear,
            // cYear = 1921 + m
            cMonth = k - n + 1
            cDay = total
            if (k === 12) {
              if (cMonth === Math.floor(CalendarData[m] / 0x10000) + 1) {
                cMonth = 1 - cMonth
              }
              if (cMonth > Math.floor(CalendarData[m] / 0x10000) + 1) {
                cMonth--
              }
            }
            // let run = ''
            let cDayStr = numString.charAt(cDay - 1)
            /* if (cMonth < 1) {
              run = '(闰)'
            } */
            if (cDay % 10 !== 0 || cDay === 10) {
              cDayStr = numString.charAt((cDay - 1) % 10)
            }
            return cDay === 1 ? monString.charAt(cMonth - 1) + '月' : (cDay < 11 ? '初' : (cDay < 20 ? '十' : (cDay < 30 ? '廿' : '三十'))) + cDayStr // tgString.charAt((cYear - 4) % 10) + dzString.charAt((cYear - 4) % 12) + '年 ' + run + monString.charAt(cMonth - 1) + '月' +
          }
        },
        getBit (m, n) { // 也是拷贝的,不是很明白这段代码干嘛的,不过很明显是处理二进制数据的
          return 29 + ((m >> n) & 1)
        }
      }
    }

    OK,代码就这些,有需要的话随便取用,除了我也不是很明白的农历日期计算之外,其他都是我写得简单代码,没什么技术含量,也就不需要赘述了

    展开全文
  • 农历日历的DatePicker控件!Xamarin控件开发小记 原文:带农历日历的DatePicker控件!Xamarin控件开发小记闲来无事开发了个日期选择控件,感兴趣的同学前往: ...这是一个带有农历日...
    原文:带农历日历的DatePicker控件!Xamarin控件开发小记

    闲来无事开发了个日期选择控件,感兴趣的同学前往:

    https://github.com/MatoApps/Mato.DatePicker

    Mato.DatePicker

    avatar

    说明

    1. 这是一个带有农历日历的日期选择Xamarin控件
    2. 可以指定初始日期
    3. 多选和单选日期

    引用

    1. PCL:https://www.nuget.org/packages/Mato.DatePicker.PCL/
    2. Android:https://www.nuget.org/packages/Mato.DatePicker.Android/
    3. iOS: https://www.nuget.org/packages/Mato.DatePicker.iOS/

    用法

    1. 在引用iOS安装包时候需要在AppDelegate.cs做如下操作:
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
    ...
        global::Xamarin.Forms.Forms.Init();   
        Mato.DatePicker.iOS.ChinaDateServer ssChinaDateServer=new Mato.DatePicker.iOS.ChinaDateServer(); //在此插入这段语句
        LoadApplication(new App());
    }

     

    同样的,在引用Android安装包后,需要在MainActivity.cs做如下操作:

    protected override void OnCreate(Bundle bundle)
    {
    ...
        global::Xamarin.Forms.Forms.Init(this, bundle);
        DatePicker.Android.ChinaDateServer ssChinaDateServer = new DatePicker.Android.ChinaDateServer(); //在此插入这段语句
        LoadApplication(new App());
    }

     

    1. 在这个页面中提供了如何使用这一控件https://github.com/MatoApps/Mato.DatePicker/blob/master/Mato.Sample/Mato.Sample/MainPage.xaml
    posted on 2018-09-21 21:49 NET未来之路 阅读(...) 评论(...) 编辑 收藏

    转载于:https://www.cnblogs.com/lonelyxmas/p/9688629.html

    展开全文
  • 农历日历小工具

    2012-05-16 17:56:07
    农历日历小工具 win7小工具:数字时钟 显示农历日历美化版 1、将日历修改了一下,日历增加几个按钮,方便操作,颜色、布局稍微调整,代码稍微优化 2、时钟页面字体颜色调整,将刺眼颜色修改成深色系,并修改显示...
  • 漂亮的VB桌面日历,不但会显示天气预报,带有农历,还能显示甲、乙、"丙、盯戊、己、庚、辛等古代历法,另外还会显示星座及星期几,如果这一天是情人节,它还会提示你,你的Ip它也将获取出来告诉你,一个透明的小...
  • 昨天实现了一个日历控件,主要包含公历和农历的展示,今天将其完成全部功能,主要包含节假日的展示、二十四节气展示。支持手势滑动显示下一个月.如实现不合理的地方希望大家提供宝贵的意见。
  • 日历控件带农历

    2006-02-23 09:05:59
    日历控件带农历
  • 带农历日历

    2009-07-20 21:07:00
    // 该物件属性 .year .month .day .isLeap .yearCyl .dayCyl .monCyl function Lunar(objDate) {  var i, leap=0, temp=0  var baseDate = new Date(1900,0,31)  var offset = (objDate - baseDate)/86400000...

    <!--  中国农历开始  -->
    <SCRIPT language=JavaScript>
    <!--
    var lunarInfo=new Array(
    0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
    0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
    0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
    0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
    0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
    0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,
    0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
    0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,
    0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
    0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
    0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
    0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
    0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
    0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
    0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0)
    var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪");
    var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
    var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
    var now = new Date();
    var SY = now.getYear();
    var SM = now.getMonth();
    var SD = now.getDate();

    function cyclical(num) { return(Gan[num%10]+Zhi[num%12]) } //==== 传入 offset 传回干支, 0=甲子
    //==== 传回农历 y年的总天数
    function lYearDays(y) {
       var i, sum = 348
       for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0
       return(sum+leapDays(y))
    }

    //==== 传回农历 y年闰月的天数
    function leapDays(y) {
       if(leapMonth(y))  return((lunarInfo[y-1900] & 0x10000)? 30: 29)
       else return(0)
    }

    //==== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
    function leapMonth(y) { return(lunarInfo[y-1900] & 0xf)}

    //====================================== 传回农历 y年m月的总天数
    function monthDays(y,m) { return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 )}

    //==== 算出农历, 传入日期物件, 传回农历日期物件
    //     该物件属性有 .year .month .day .isLeap .yearCyl .dayCyl .monCyl
    function Lunar(objDate) {
       var i, leap=0, temp=0
       var baseDate = new Date(1900,0,31)
       var offset   = (objDate - baseDate)/86400000

       this.dayCyl = offset + 40
       this.monCyl = 14

       for(i=1900; i<2050 && offset>0; i++) {
          temp = lYearDays(i)
          offset -= temp
          this.monCyl += 12
       }
       if(offset<0) {
          offset += temp;
          i--;
          this.monCyl -= 12
       }

       this.year = i
       this.yearCyl = i-1864

       leap = leapMonth(i) //闰哪个月
       this.isLeap = false

       for(i=1; i<13 && offset>0; i++) {
          //闰月
          if(leap>0 && i==(leap+1) && this.isLeap==false)
             { --i; this.isLeap = true; temp = leapDays(this.year); }
          else
             { temp = monthDays(this.year, i); }

          //解除闰月
          if(this.isLeap==true && i==(leap+1)) this.isLeap = false

          offset -= temp
          if(this.isLeap == false) this.monCyl ++
       }

       if(offset==0 && leap>0 && i==leap+1)
          if(this.isLeap)
             { this.isLeap = false; }
          else
             { this.isLeap = true; --i; --this.monCyl;}

       if(offset<0){ offset += temp; --i; --this.monCyl; }

       this.month = i
       this.day = offset + 1
    }

    function YYMMDD(){
        var cl = '<font color="green" STYLE="font-size:13pt;">';
        if (now.getDay() == 0) cl = '<font color="#c00000" STYLE="font-size:13pt;">';
        if (now.getDay() == 6) cl = '<font color="green" STYLE="font-size:13pt;">';
        return(cl+SY+'年'+(SM+1)+'月'+'</font>');
    }
    function weekday(){
        var day = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
        var cl = '<font color="green" STYLE="font-size:9pt;">';
        if (now.getDay() == 0) cl = '<font color="green" STYLE="font-size:9pt;">';
        if (now.getDay() == 6) cl = '<font color="red" STYLE="font-size:9pt;">';
        return(cl+ day[now.getDay()]+ '</font>');
    }
    //==== 中文日期
    function cDay(m,d){
    var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十');
    var nStr2 = new Array('初','十','廿','卅',' ');
    var s;
    if (m>10){s = '十'+nStr1[m-10]} else {s = nStr1[m]} s += '月'
    switch (d) {
      case 10:s += '初十'; break;
      case 20:s += '二十'; break;
      case 30:s += '三十'; break;
      default:s += nStr2[Math.floor(d/10)]; s += nStr1[d%10];
    }
    return(s);
    }
    function solarDay1(){
        var sDObj = new Date(SY,SM,SD);
        var lDObj = new Lunar(sDObj);
        var cl = '<font color="#9933CC" STYLE="font-size:9pt;">';
        var tt = '【'+Animals[(SY-4)%12]+'】'+cyclical(lDObj.monCyl)+'月 '+cyclical(lDObj.dayCyl++)+'日' ;
        return(cl+tt+'</font>');
    }
    function solarDay2(){
        var sDObj = new Date(SY,SM,SD);
        var lDObj = new Lunar(sDObj);
        var cl = '<font color="green" STYLE="font-size:9pt;">';
        //农历BB'+(cld[d].isLeap?'闰 ':' ')+cld[d].lMonth+' 月 '+cld[d].lDay+' 日
        var tt = cyclical(SY-1900+36)+'年 '+cDay(lDObj.month,lDObj.day);
        return(cl+tt+'</font>');
    }
    function solarDay3(){
    var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758)
    var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至")
    var lFtv = new Array("0101*春节","0115 元宵节","0505 端午节","0707 七夕情人节","0715 中元节","0815 中秋节","0909 重阳节","1208 腊八节","1224 小年","0100*除夕")
    var sFtv = new Array("0101*元旦","0214 情人节","0308 妇女节","0309 偶今天又长一岁拉","0312 植树节","0315 消费者权益日","0401 愚人节","0418 MM的生日","0501 劳动节","0504 青年节","0512 护士节","0601 儿童节","0701 建党节 香港回归纪念","0801 建军节","0808 父亲节","0909 毛席逝世纪念","0910 教师节","0928 孔子诞辰","1001*国庆节",
    "1006 老人节","1024 联合国日","1112 孙中山诞辰","1220 澳门回归纪念","1225 圣诞节","1226 毛席诞辰")

      var sDObj = new Date(SY,SM,SD);
      var lDObj = new Lunar(sDObj);
      var lDPOS = new Array(3)
      var festival='',solarTerms='',solarFestival='',lunarFestival='',tmp1,tmp2;
      //农历节日
      for(i in lFtv)
      if(lFtv[i].match(/^(/d{2})(.{2})([/s/*])(.+)$/)) {
       tmp1=Number(RegExp.$1)-lDObj.month
       tmp2=Number(RegExp.$2)-lDObj.day
       if(tmp1==0 && tmp2==0) lunarFestival=RegExp.$4
      }
      //国历节日
      for(i in sFtv)
      if(sFtv[i].match(/^(/d{2})(/d{2})([/s/*])(.+)$/)){
       tmp1=Number(RegExp.$1)-(SM+1)
       tmp2=Number(RegExp.$2)-SD
       if(tmp1==0 && tmp2==0) solarFestival = RegExp.$4
      }
      //节气
      tmp1 = new Date((31556925974.7*(SY-1900)+sTermInfo[SM*2+1]*60000)+Date.UTC(1900,0,6,2,5))
      tmp2 = tmp1.getUTCDate()
      if (tmp2==SD) solarTerms = solarTerm[SM*2+1] 
      tmp1 = new Date((31556925974.7*(SY-1900)+sTermInfo[SM*2]*60000)+Date.UTC(1900,0,6,2,5))
      tmp2= tmp1.getUTCDate()
      if (tmp2==SD) solarTerms = solarTerm[SM*2]

      if(solarTerms == '' && solarFestival == '' && lunarFestival == '')
        festival = '';
      else
        festival = '<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#CCFFCC"><TR><TD align=center><marquee direction=left scrolldelay=120 behavior=alternate>'+
        '<FONT COLOR="#FF33FF" STYLE="font-size:9pt;"><b>'+solarTerms + ' ' + solarFestival + ' ' + lunarFestival+'</b></FONT></marquee></TD>'+
        '</TR></TABLE>';
            
      var cl = '<font color="green" STYLE="font-size:9pt;">';
      return(cl+festival+'</font>');
    }

    //显示当前时间
    function CurentTime()
    {
        var now = new Date();
        var hh = now.getHours();
        var mm = now.getMinutes();
        var ss = now.getTime() % 60000;
        ss = (ss - (ss % 1000)) / 1000;
        var clock = hh+':';
        if (mm < 10) clock += '0';
        clock += mm+':';
        if (ss < 10) clock += '0';
        clock += ss;
        return(clock);
    }

    function refreshCalendarClock() //
    {
     document.all.ClockTime.innerHTML = CurentTime();
    }
    //显示当前时间

    function setCalendar(){
    document.write("<table border='1' cellspacing='3' width='180' bordercolor='#009B00' bgcolor='#FFFFFF' height='110' cellpadding='2'>");
    document.write("<tr><td align='center'><b>"+YYMMDD()+"<br><font face='Arial' size='6' color=#FF8040>"+SD+"</font><br>");
    document.write(weekday()+"<br><font id=ClockTime color=red></font>"+"<br></b>");
    document.write(solarDay1()+"<br>"+solarDay2()+"<br>"+solarDay3()+"</td></tr></table>");

    }
    setCalendar();
    setInterval('refreshCalendarClock()',1000);//1秒钟刷新1次当前时间
    //-->
    </SCRIPT>
    <!--结束-->

    展开全文
  • Qt 制作带农历日历

    万次阅读 2016-05-05 09:37:58
    网上农历算法很多,大部分都是比较准的,但是在Qt里面很少朋友整理和共享出来,在此,花一点时间整理下资料和想法,顺便或许也能帮助一些新手朋友! 首先讲讲设计思路吧,没有采用系统自带的QCalendarWidget,而是...

    网上农历算法很多,大部分都是比较准的,但是在Qt里面很少有朋友整理和共享出来,在此,花一点时间整理下资料和想法,顺便或许也能帮助一些新手朋友!

    首先讲讲设计思路吧,没有采用系统自带的QCalendarWidget,而是通过42个QLabel拼凑出来的一个界面,之所以采用这种拼凑的方法是方便管理样式,话不多说了上图和代码吧:


    先来界面布局代码吧:


    #ifndef CALENDARWIDGET_H
    #define CALENDARWIDGET_H
    
    #include <QWidget>
    #include <QLabel>
    
    QT_BEGIN_NAMESPACE
    class QPushButton;
    class QComboBox;
    class QGroupBox;
    class QLineEdit;
    class QDate;
    class QGridLayout;
    class QHBoxLayout;
    class QVBoxLayout;
    
    class Event;
    class DataBase;
    QT_END_NAMESPACE
    
    typedef enum {
        Sunday,
        Monday,
        Tuesday,
        Wednesday,
        Thursday,
        Friday,
        Saturday,
        Week
    } E_WEEK;
    
    typedef enum {
        PREV_MONTH_DAY,     // 上月剩余天数
        NEXT_MONTH_DAY,     // 下个月的天数
        CURR_MONTH_DAY,     // 当月天数
        WEEKEND_DAY,        // 周末
        CURRENT_DAY,        // 当天
    } E_DAY;
    
    ///
    /// \brief The DayLabel class
    /// 自定义的日子显示控件
    ///
    class DayLabel : public QLabel {
        Q_OBJECT
    
    public:
        explicit DayLabel(QWidget *parent = 0);
    
        bool bSelect;
        bool getBSelect() const;
        void setSelected(bool value);
        void setColor(const int &type);
        void showDay(int nDay, QString strLunar);
    
        int m_nDay;
        void setPlan(QStringList plan);
    signals:
        void signalClicked(int ntype, int day);
        void signalPlan(const QString &content);
    private:
        QLabel *labelIcon;
        QStringList m_strListPlan;
    protected:
        void enterEvent(QEvent *e);
        void leaveEvent(QEvent *e);
        void mousePressEvent(QMouseEvent *e);
        void mouseDoubleClickEvent(QMouseEvent *e);
    };
    
    /
    /// \brief The CalendarWidget class
    /// 日历界面
    
    class CalendarWidget : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit CalendarWidget(QWidget *parent = 0);
        ~CalendarWidget();
    
        int year() const;
        void setYear(int year);
    
        int month() const;
        void setMonth(int month);
    
        int day() const;
        void setDay(int day);
    
        void jumpTodate(int year, int month, int day);
    signals:
        void signalDayClicked(int nday);
        void signalDayChanged();
        void signalPlan(const QString &content);
    private:
        QVBoxLayout *verLayoutCalendar;
    
        QWidget *widgetTitle;
        QLabel *labelTitle;
        QPushButton *btnPrevMonth;
        QPushButton *btnNextMonth;
        QHBoxLayout *horLayoutTitle;
    
        QWidget *widgetWeek;
        QLabel *labelWeek[Week];
        QHBoxLayout *horLayoutWeek;
    
        QWidget *widgetBody;
        DayLabel *labelDay[42];
        QGridLayout *gridLayoutBody;
    
        QWidget *widgetRight;
    
        QLabel *labelShowToday;
        QLabel *labelShowWeek;
        QLabel *labelShowDay;
        QLabel *labelShowNYear;
        QLabel *labelShowLunarDate;
        QLabel *labelSpacer;
        QLabel *labelScheduleTitle;
        QLabel *labelSchedule;
    
        QVBoxLayout *verlayoutWidgetRight;
    
        QHBoxLayout *horLayoutGlobal;
    
    private:
        int m_nYear;
        int m_nMonth;
        int m_nDay;
    private:
        void initWidget();<pre name="code" class="cpp">#include "calendarwidget.h"
    .cpp
    
    #include "date.h"
    #include "database.h"
    
    #include <QInputDialog>
    #include <QPainter>
    #include <QStyleOption>
    #include <QDateTime>
    #include <QPushButton>
    #include <QLineEdit>
    #include <QGroupBox>
    #include <QLabel>
    #include <QDate>
    #include <QGridLayout>
    #include <QHBoxLayout>
    #include <QVBoxLayout>
    #include <QSpacerItem>
    #include <QDebug>
    #include <QFont>
    
    static const QString s_strWeek[] = {
        QObject::tr("周日"), QObject::tr("周一"), QObject::tr("周二"),
        QObject::tr("周三"), QObject::tr("周四"), QObject::tr("周五"),
        QObject::tr("周六"),
    };
    
    CalendarWidget::CalendarWidget(QWidget *parent)
        : QWidget(parent), m_nMonth(1)
    {
        // 获取当前年月日
        m_nYear  = QDate::currentDate().year();
        m_nMonth = QDate::currentDate().month();
        m_nDay = QDate::currentDate().day();
    
        initWidget();
        initDate();
    }
    
    CalendarWidget::~CalendarWidget()
    {
    
    }
    
    int CalendarWidget::year() const
    {
        return m_nYear;
    }
    
    void CalendarWidget::setYear(int nYear)
    {
        m_nYear = nYear;
    }
    
    int CalendarWidget::month() const
    {
        return m_nMonth;
    }
    
    void CalendarWidget::setMonth(int nMonth)
    {
        m_nMonth = nMonth;
    }
    
    int CalendarWidget::day() const
    {
        return m_nDay;
    }
    
    void CalendarWidget::setDay(int nDay)
    {
        m_nDay = nDay;
    }
    
    void CalendarWidget::jumpTodate(int year, int month, int day)
    {
        setYear(year);
        setMonth(month);
        setDay(day);
    
        initDate();
    }
    
    /**
     * @brief CalendarWidget::initWidget 初始化界面
     */
    void CalendarWidget::initWidget()
    {
    #ifdef Q_OS_ANDROID
        this->setMinimumSize(1400, 800);
    #else
        this->setMinimumSize(427, 350);
        this->setObjectName("widgetCalendar");
    #endif
    
        verLayoutCalendar = new QVBoxLayout(this);
        verLayoutCalendar->setContentsMargins(2, 2, 2, 2);
        verLayoutCalendar->setSpacing(0);
    
        //! [2]
        widgetTitle = new QWidget(this);
        widgetTitle->setObjectName("widgetTitle");
    
    #ifdef Q_OS_ANDROID
        widgetTitle->setFixedHeight(80);
    #else
        widgetTitle->setMinimumHeight(20);
    #endif
    
        btnPrevMonth = new QPushButton(widgetTitle);
        btnPrevMonth->setText(tr("上月"));
    
        labelTitle = new QLabel(widgetTitle);
        labelTitle->setAlignment(Qt::AlignCenter);
        labelTitle->setObjectName("labelTitle");
        labelTitle->setText(tr("2016 年 04 月"));
    
        btnNextMonth = new QPushButton(widgetTitle);
        btnNextMonth->setText(tr("下月"));
    
        horLayoutTitle = new QHBoxLayout(widgetTitle);
        horLayoutTitle->addWidget(btnPrevMonth);
        horLayoutTitle->addWidget(labelTitle, 1);
        horLayoutTitle->addWidget(btnNextMonth);
    
        verLayoutCalendar->addWidget(widgetTitle);
    
        connect(btnPrevMonth, SIGNAL(clicked(bool)), this, SLOT(sltShowPrevMonth()));
        connect(btnNextMonth, SIGNAL(clicked(bool)), this, SLOT(sltShowNextMonth()));
        //! [2]
    
        //! [3]
        widgetWeek = new QWidget(this);
        widgetWeek->setObjectName("widgetWeek");
    
        horLayoutWeek = new QHBoxLayout(widgetWeek);
        horLayoutWeek->setContentsMargins(0, 0, 0, 0);
        horLayoutWeek->setSpacing(0);
    
        for (int i = 0; i < Week; i++) {
            labelWeek[i] = new QLabel(widgetWeek);
            labelWeek[i]->setText(s_strWeek[i]);
            labelWeek[i]->setObjectName("labelWeek");
            labelWeek[i]->setMinimumHeight(30);
            labelWeek[i]->setAlignment(Qt::AlignCenter);
            if ((0 == (i % 7)) || (6 == (i% 7))) {
                labelWeek[i]->setProperty("weekend", true);
            }
            horLayoutWeek->addWidget(labelWeek[i]);
        }
    
        verLayoutCalendar->addWidget(widgetWeek);
        //! [3]
    
        //! [4]
        widgetBody = new QWidget(this);
        verLayoutCalendar->addWidget(widgetBody, 1);
    
        gridLayoutBody = new QGridLayout(widgetBody);
        gridLayoutBody->setHorizontalSpacing(0);
        gridLayoutBody->setVerticalSpacing(0);
        gridLayoutBody->setContentsMargins(0, 0, 0, 0);
    
        for (int i = 0; i < 42; i++) {
            labelDay[i] = new DayLabel(widgetBody);
            labelDay[i]->setObjectName("labelDay");
            labelDay[i]->setAlignment(Qt::AlignCenter);
            labelDay[i]->setText(QString::number(i));
            if ((0 == (i % 7)) || (6 == (i% 7))) {
                labelDay[i]->setProperty("weekend", true);
            }
            gridLayoutBody->addWidget(labelDay[i], i / 7, i % 7);
            connect(labelDay[i], SIGNAL(signalClicked(int,int)), this, SLOT(sltDayClicked(int,int)));
            connect(labelDay[i], SIGNAL(signalPlan(QString)), this, SIGNAL(signalPlan(QString)));
        }
    
        labelDay[10]->setSelected(true);
        //! [4]
    }
    
    /**
     * @brief CalendarWidget::initDate 初始化日期
     */
    void CalendarWidget::initDate()
    {
        // 首先判断当前月的第一天是星期几
        int nWeek  = Date::getFirstDayOfWeek(m_nYear, m_nMonth);
        int nMonthDays = Date::getMonthDays(m_nYear, m_nMonth);
        // 上月天数
        int nPreMonDays = Date::getMonthDays(1 == m_nMonth ? m_nYear - 1 : m_nYear, 1 == m_nMonth ? 12 : m_nMonth - 1);
    
        // 显示当前年月
        labelTitle->setText(tr("%1 年 %2 月")
                            .arg(m_nYear, 2, 10, QChar('0'))
                            .arg(m_nMonth, 2, 10, QChar('0')));
    
        // 显示上月剩余天数
        if (0 == nWeek) {
            // 显示上月天数
            for (int i = 0; i < 7; i++) {
                labelDay[i]->showDay((nPreMonDays - 7 + i + 1), "");
                labelDay[i]->setColor(PREV_MONTH_DAY);
            }
            // 显示下月天数
            for (int i = 0; i < (42 - nMonthDays - 7); i++) {
                labelDay[nMonthDays + 7 + i]->showDay((i + 1), "");
                labelDay[nMonthDays + 7 + i]->setColor(NEXT_MONTH_DAY);
            }
        }
        else {
            for (int i = 0; i < nWeek; i++) {
                labelDay[i]->showDay((nPreMonDays - nWeek + i + 1), "");
                labelDay[i]->setColor(PREV_MONTH_DAY);
            }
    
            // 显示下月天数
            for (int i = (nWeek + nMonthDays); i < 42; i++) {
                labelDay[i]->showDay((i - (nWeek + nMonthDays) + 1), "");
                labelDay[i]->setColor(NEXT_MONTH_DAY);
            }
        }
    
        // 显示当前月
        int nProperty = 1;
        QStringList strPlan;
        int index = 0;
        for (int i = nWeek; i < (nMonthDays + nWeek); i++) {
            index = 0 == nWeek ? (i + 7) : i;
            labelDay[index]->showDay(i - nWeek + 1, Date::getLunarDate(m_nYear, m_nMonth, i - nWeek + 1));
            nProperty = ((0 == (i % 7)) || (6 == (i% 7))) ? WEEKEND_DAY : CURR_MONTH_DAY;
            labelDay[index]->setColor(nProperty);
            // 显示计划
            strPlan = DataBase::selectDb(
                        QString("%1-%2-%3")
                        .arg(m_nYear, 4, 10,  QChar('0'))
                        .arg(m_nMonth, 2, 10, QChar('0'))
                        .arg(i - nWeek + 1, 2, 10,   QChar('0')));
    
            // 显示计划
            labelDay[index]->setPlan(strPlan);
        }
    
        // 显示当前天数
        labelDay[m_nDay + nWeek - 1]->setColor(CURRENT_DAY);
        // 发送更新信号
        Q_EMIT signalDayChanged();
    }
    
    /**
     * @brief CalendarWidget::sltDayClicked 点击响应
     * @param type  类型 0 表示上月 1表示下月
     * @param day  当前点击的天数
     */
    void CalendarWidget::sltDayClicked(int type, int day)
    {
        // 上月
        if (PREV_MONTH_DAY == type) {
            sltShowPrevMonth();
        }
        // 下月
        else if (NEXT_MONTH_DAY == type) {
            sltShowNextMonth();
        }
        // 当天/周末/当月天数都显示在右边,并转换成农历
        else if ((CURR_MONTH_DAY == type)
                 || (WEEKEND_DAY == type)
                 || (CURRENT_DAY == type)) {
            // 选中当天
            Q_EMIT signalDayClicked(day);
        }
    }
    
    /**
     * @brief CalendarWidget::sltShowPrevMonth 显示上月日期
     */
    void CalendarWidget::sltShowPrevMonth()
    {
        m_nMonth--;
        if (m_nMonth < 1) {
            m_nMonth = 12;
            m_nYear--;
        }
    
        initDate();
    }
    
    /**
     * @brief CalendarWidget::sltShowNextMonth 显示下月日期
     */
    void CalendarWidget::sltShowNextMonth()
    {
        m_nMonth++;
        if (m_nMonth > 12) {
            m_nMonth = 1;
            m_nYear++;
        }
        initDate();
    }
    
    //
    /// \brief DayLabel::DayLabel
    /// \param parent
    
    
    #include <QMouseEvent>
    #include <QEvent>
    #include <QPixmap>
    #include "event.h"
    
    DayLabel::DayLabel(QWidget *parent):
        QLabel(parent)
    {
        bSelect = false;
        m_nDay = 0;
        m_strListPlan.clear();
    
        labelIcon = new QLabel(this);
        labelIcon->setFixedSize(QSize(12, 12));
        labelIcon->setPixmap(QPixmap(":/images/eventindicator.png"));
        labelIcon->move(0, 0);
        labelIcon->setVisible(false);
    }
    
    bool DayLabel::getBSelect() const
    {
        return bSelect;
    }
    
    void DayLabel::setSelected(bool value)
    {
        bSelect = value;
        this->setStyleSheet(QString("background: #ffffff; border: 1px solid red; border-radius: 2px"));
    }
    
    void DayLabel::setColor(const int &type)
    {
        // 设置控件属性类型
        this->setProperty("type", type);
        this->setSelected(CURRENT_DAY == type);
    
        // 其他月
        if ((PREV_MONTH_DAY == type) || (NEXT_MONTH_DAY == type)) {
            this->setStyleSheet("background: #ffffff; border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; color: #999999;");
            labelIcon->setVisible(false);
        }
        // 当前月
        else if (CURR_MONTH_DAY == type) {
            this->setStyleSheet("background: #ffffff; border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; color: #000000;");
        }
        // 周末
        else if (WEEKEND_DAY == type) {
            labelIcon->setVisible(false);
            this->setStyleSheet("background: #ffffff; border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; color: #ff0000;");
        }
    }
    
    /**
     * @brief DayLabel::showDay
     * @param nDay
     * @param strLunar
     * @param type
     */
    void DayLabel::showDay(int nDay, QString strLunar)
    {
        QString strText = QString::number(nDay);
        this->m_nDay = nDay;
    
        if ("" != strLunar) {
            strText.append("\n");
            strText.append(strLunar);
        }
    
        this->setText(strText);
    }
    
    /**
     * @brief DayLabel::setPlan 设置计划和日程
     * @param plan
     */
    void DayLabel::setPlan(QStringList plan)
    {
        if (!plan.isEmpty()) {
            m_strListPlan = plan;
            this->setToolTip(m_strListPlan.at(1));
        }
        else {
            labelIcon->setVisible(false);
            m_strListPlan.clear();
        }
    }
    
    void DayLabel::enterEvent(QEvent *e)
    {
        int nProperty = this->property("type").toInt();
        if (PREV_MONTH_DAY == nProperty || NEXT_MONTH_DAY == nProperty) return;
    
        this->setStyleSheet("background: #c8b9a6; border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3;");
        QLabel::enterEvent(e);
    }
    
    void DayLabel::leaveEvent(QEvent *e)
    {
        int nProperty = this->property("type").toInt();
        if (PREV_MONTH_DAY == nProperty || NEXT_MONTH_DAY == nProperty) return;
    
        if (bSelect) {
            this->setStyleSheet("background: #ffffff; border: 1px solid red;");
        }
        else {
            this->setStyleSheet("background: #ffffff; border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3;");
        }
        QLabel::leaveEvent(e);
    }
    
    void DayLabel::mousePressEvent(QMouseEvent *e)
    {
    //    qDebug() << this->text() << this->property("type").toInt();
        Q_EMIT signalClicked(this->property("type").toInt(), m_nDay);
        if (!m_strListPlan.isEmpty()) {
            Q_EMIT signalPlan(m_strListPlan.at(1));
        }
        else {
             Q_EMIT signalPlan(tr("没有日程安排"));
        }
        QLabel::mousePressEvent(e);
    }
    
    void DayLabel::mouseDoubleClickEvent(QMouseEvent *e)
    {
        //    qDebug() << "double";
        int nProperty = this->property("type").toInt();
        if (PREV_MONTH_DAY == nProperty || NEXT_MONTH_DAY == nProperty) return;
    
        bool ok;
        QString strText = "";
        if (!m_strListPlan.isEmpty()) {
            strText = m_strListPlan.at(1);
        }
    
        strText = QInputDialog::getText(this, tr("修改日程"),
                                             tr("您的出行计划"), QLineEdit::Normal,
                                             strText, &ok);
        if (ok && !strText.isEmpty())
            qDebug() << strText;
        QLabel::mouseDoubleClickEvent(e);
    }
    
    //
    /// \brief Window::Window
    /// \param parent
    /
    
    #include <QMessageBox>
    #include "database.h"
    
    Window::Window(QWidget *parent) :
        QWidget(parent)
    {
        // 初始化数据库
        DataBase::connectdb();
    
        initWidget();
        initStyle();
        initDatabase();
    }
    
    Window::~Window()
    {
    }
    
    void Window::initWidget()
    {
        //! [1]
        calendar = new CalendarWidget(this);
        //! [1]
    
        //! [2]
        widgetRight     = new QWidget(this);
        widgetRight->setObjectName("widgetRight");
    //    widgetRight->setMinimumSize(160, 350);
    
        labelShowToday       = new QLabel(widgetRight);
        labelShowWeek        = new QLabel(widgetRight);
        labelShowDay         = new QLabel(widgetRight);
        labelShowNYear       = new QLabel(widgetRight);
        labelShowLunarDate   = new QLabel(widgetRight);
        labelSpacer          = new QLabel(widgetRight);
        labelPlanTitle   = new QLabel(widgetRight);
        labelShowPlan        = new QLabel(widgetRight);
    
        labelShowToday->setAlignment(Qt::AlignCenter);
        labelShowWeek->setAlignment(Qt::AlignCenter);
        labelShowDay->setAlignment(Qt::AlignCenter);
        labelShowNYear->setAlignment(Qt::AlignCenter);
        labelShowLunarDate->setAlignment(Qt::AlignCenter);
        labelSpacer->setFixedSize(widgetRight->width(), 2);
    
        labelShowToday->setObjectName("labelCommon");
        labelShowWeek->setObjectName("labelCommon");
        labelShowDay->setObjectName("labelShowDay");
        labelShowNYear->setObjectName("labelCommon");
        labelShowLunarDate->setObjectName("labelCommon");
        labelSpacer->setObjectName("labelSpacer");
        labelPlanTitle->setObjectName("labelCommon");
        labelShowPlan->setObjectName("labelSchedule");
    
        labelShowToday->setText(QDateTime::currentDateTime().toString("yyyy 年 MM 月 dd日"));
        labelShowWeek->setText(QDate::currentDate().toString("ddd"));
        labelShowDay->setText(QDate::currentDate().toString("dd"));
        labelShowNYear->setText(tr("丙申猴年 壬辰月 甲子日"));
        labelShowLunarDate->setText(tr("农历 三月初六"));
        labelPlanTitle->setText(tr("今日行程安排"));
        labelShowPlan->setText(tr("今天需要完成数据采集工作!"));
        labelShowPlan->setWordWrap(true);
    
        verlayoutWidgetRight = new QVBoxLayout(widgetRight);
        verlayoutWidgetRight->setContentsMargins(0, 0, 0, 0);
        verlayoutWidgetRight->setSpacing(15);
        verlayoutWidgetRight->addWidget(labelShowToday);
        verlayoutWidgetRight->addWidget(labelShowWeek);
        verlayoutWidgetRight->addWidget(labelShowDay);
        verlayoutWidgetRight->addWidget(labelShowNYear);
        verlayoutWidgetRight->addWidget(labelShowLunarDate);
        verlayoutWidgetRight->addWidget(labelSpacer, 0, Qt::AlignCenter);
        verlayoutWidgetRight->addStretch(1);
        verlayoutWidgetRight->addWidget(labelPlanTitle);
        verlayoutWidgetRight->addWidget(labelShowPlan, 1);
        //! [2]
    
        horLayoutWidget = new QHBoxLayout();
        horLayoutWidget->addWidget(calendar, 3, Qt::AlignCenter);
        horLayoutWidget->addWidget(widgetRight, 1);
    
        //! [3]
        groupBoxBottom = new QGroupBox(this);
    
        labelYearJump = new QLabel(groupBoxBottom);
        labelMonthJump = new QLabel(groupBoxBottom);
        labelDayJump = new QLabel(groupBoxBottom);
    
        labelYearJump->setMinimumWidth(20);
        labelMonthJump->setMinimumWidth(20);
        labelDayJump->setMinimumWidth(20);
    
        labelYearJump->setObjectName("labelCommon");
        labelMonthJump->setObjectName("labelCommon");
        labelDayJump->setObjectName("labelCommon");
    
        labelYearJump->setText(tr("年:"));
        labelMonthJump->setText(tr("月:"));
        labelDayJump->setText(tr("日:"));
        ///
    
        editYearJump = new QLineEdit(groupBoxBottom);
        editMonthJump = new QLineEdit(groupBoxBottom);
        editDayJump = new QLineEdit(groupBoxBottom);
    
        editYearJump->setMaximumWidth(60);
        editMonthJump->setMaximumWidth(60);
        editDayJump->setMaximumWidth(60);
    
        editYearJump->setText("2016");
        editMonthJump->setText("1");
        editDayJump->setText("1");
        //
    
        btnDateJump = new QPushButton(groupBoxBottom);
        btnDateJump->setText(tr("跳转至该日期"));
    
        btnToday = new QPushButton(groupBoxBottom);
        btnToday->setText(tr("返回今天"));
    
        horLayoutJump = new QHBoxLayout(groupBoxBottom);
        horLayoutJump->setSpacing(10);
        horLayoutJump->addWidget(labelYearJump);
        horLayoutJump->addWidget(editYearJump);
    
        horLayoutJump->addWidget(labelMonthJump);
        horLayoutJump->addWidget(editMonthJump);
    
        horLayoutJump->addWidget(labelDayJump);
        horLayoutJump->addWidget(editDayJump);
    
        horLayoutJump->addStretch(1);
        horLayoutJump->addWidget(btnDateJump);
        horLayoutJump->addWidget(btnToday);
    
        //! [3]
    
        //! [4]
        verLayoutAll = new QVBoxLayout(this);
        verLayoutAll->setContentsMargins(10, 10, 10, 10);
        verLayoutAll->setSpacing(10);
        verLayoutAll->addLayout(horLayoutWidget, 1);
        verLayoutAll->addWidget(groupBoxBottom, 0);
    
        //! [4]
        connect(calendar, SIGNAL(signalDayChanged()), this, SLOT(sltDayChanged()));
        connect(calendar, SIGNAL(signalDayClicked(int)), this, SLOT(sltDayClicked(int)));
        connect(calendar, SIGNAL(signalPlan(QString)), this, SLOT(sltShowPlans(QString)));
        connect(btnDateJump, SIGNAL(clicked(bool)), this, SLOT(sltDateJump()));
        connect(btnToday, SIGNAL(clicked(bool)), this, SLOT(sltBack2today()));
    }
    
    void Window::initDatabase()
    {
    }
    
    
    /**
     * @brief CalendarWidget::initStyle 初始化样式
     */
    void Window::initStyle()
    {
        QString strStyle = "";
    #ifdef Q_OS_ANDROID
        strStyle += QString(".CalendarWidget {border: 1px solid #ff00ff;}");
        strStyle += QString(".Window {background: black;}");
        strStyle += QString(".DayLabel{font-size: 64px;}");
        strStyle += QString("QWidget#widgetRight{background-color: transparent;}");
        strStyle += QString("QWidget#widgetCalendar{ background-color: white;}");
        strStyle += QString("QWidget#widgetTitle{ background-color: #c8b9a6;}");
        strStyle += QString("QWidget#widgetWeek{ background-color: #efefef;}");
        strStyle += QString("QLabel#labelTitle {border: none; font: bold 18px;}");
        strStyle += QString("QLabel#labelWeek {border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; font: bold 12px;}");
        strStyle += QString("QLabel#labelDay[weekend=true],QLabel#labelWeek[weekend=true]{color: red;}");
        strStyle += QString("QLabel#labelDay {border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; font-size: 14px;}");
        strStyle += QString("QLabel#labelShowDay {color: yellow; font: bold 64px;}");
        strStyle += QString("QLabel#labelCommon {background-color: transparent;color: #ffffff;}");
        strStyle += QString("QLabel#labelSchedule {background-color: transparent;color: #ffffff; border: 1px solid #ffffff;}");
        strStyle += QString("QLabel#labelSpacer {border: 1px solid #ffffff;}");
        strStyle += QString("QLineEdit {border: 1px solid #ffffff; border-radius: 5px; font-size: 20px;}");
    
    #else
        strStyle += QString(".CalendarWidget {border: 1px solid #ff00ff;}");
        strStyle += QString(".Window {background: black;}");
        strStyle += QString(".DayLabel{font: 24px; font-family: 隶书;}");
        strStyle += QString("QWidget#widgetCalendar{ background-color: white;}");
        strStyle += QString("QWidget#widgetTitle{ background-color: #c8b9a6;}");
        strStyle += QString("QWidget#widgetWeek{ background-color: #efefef;}");
        strStyle += QString("QLabel#labelTitle {border: none; font: bold 18px;}");
        strStyle += QString("QLabel#labelWeek {border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; font: bold 12px;}");
        strStyle += QString("QLabel#labelDay[weekend=true],QLabel#labelWeek[weekend=true]{color: red;}");
        strStyle += QString("QLabel#labelDay {border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; font-size: 14px;}");
        strStyle += QString("QLabel#labelShowDay {color: yellow; font: bold 64px;}");
        strStyle += QString("QLabel#labelCommon {color: #ffffff;}");
        strStyle += QString("QLabel#labelSchedule {color: #ffffff; border: 1px solid #ffffff;}");
        strStyle += QString("QLabel#labelSpacer {border: 1px solid #ffffff;}");
        strStyle += QString("QLineEdit {border: 1px solid #ffffff; border-radius: 5px; font-size: 20px;}");
    #endif
        this->setStyleSheet(strStyle);
    }
    
    void Window::sltDayClicked(int nday)
    {
        labelShowDay->setText(QString("%1").arg(nday, 2, 10, QChar('0')));
        // 显示农历
        QString strLunar = Date::getLunarMonAndDay(calendar->year(), calendar->month(), nday);
        labelShowLunarDate->setText(tr("农历  %1").arg(strLunar));
    }
    
    void Window::sltDayChanged()
    {
        // 更新右边控件显示
        labelShowDay->setText(QString("%1").arg(calendar->day(), 2, 10, QChar('0')));
        // 显示农历
        QString strLunar = Date::getLunarMonAndDay(calendar->year(), calendar->month(), calendar->day());
        labelShowLunarDate->setText(tr("农历  %1").arg(strLunar));
        labelShowNYear->setText(Date::getLunarTime(calendar->year()));
    }
    
    // 跳转日期
    void Window::sltDateJump()
    {
        int year = editYearJump->text().toInt();
        int month = editMonthJump->text().toInt();
        int day = editDayJump->text().toInt();
        int nMaxSet = 0;
    
        if ((year > 2040) || (year < 1970)) {
            QMessageBox::information(this, tr("提示"), tr("跳转年输入错误,请重新输入!"));
            editYearJump->setFocus();
            return;
        }
    
        if ((month > 12) || (month < 1)) {
            editMonthJump->setFocus();
            QMessageBox::information(this, tr("提示"), tr("跳转月输入错误,请重新输入!"));
            return;
        }
    
        if (2 == month) {
            nMaxSet = Date::isLoopYaer(year) ? 29 : 28;
        }
        else {
            nMaxSet = 31;
        }
    
        if ((day > nMaxSet) || (day < 1)) {
            editDayJump->setFocus();
            QMessageBox::information(this, tr("提示"), tr("跳转日输入错误,请重新输入!"));
            return;
        }
        // 跳转
        calendar->jumpTodate(year, month, day);
    }
    
    /**
     * @brief Window::sltBack2today 跳转至今天
     */
    void Window::sltBack2today()
    {
        int year = QDate::currentDate().year();
        int month = QDate::currentDate().month();
        int day = QDate::currentDate().day();
    
        // 跳转
        calendar->jumpTodate(year, month, day);
    }
    
    /**
     * @brief Window::sltShowPlans 显示日程
     * @param content
     * @return
     */
    void Window::sltShowPlans(const QString &content)
    {
        labelShowPlan->setText(content);
    }
    
    void Window::paintEvent(QPaintEvent *)
    {
        QStyleOption opt;
        opt.init(this);
        QPainter p(this);
        style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    }

    然后就是农历的算法;

    </pre></p><p></p><p><pre name="code" class="cpp">#ifndef DATE_H
    #define DATE_H
    
    #include <QObject>
    
    class Date : public QObject
    {
        Q_OBJECT
    
    
    
    public:
        explicit Date(QObject *parent = 0);
    
    signals:
    
    public slots:
    
    public:
        static quint16 getSpringFestivalDate(int year);
    
        static int getFirstDayOfWeek(int year, int month);
        static int getTotalMonthDays(int year, int month);
        static int getMonthDays(int year, int month);
        static bool isLoopYaer(int year);
        static QString getLunarDate(int year, int month, int day);
        static QString getLunarMonAndDay(int year, int month, int day);
        // 计算今年是什么年如 :甲子年
        static QString getLunarTime(int year);
    private:
        static QString holiday(int month, int day);
        static QString solarTerms(int year, int month, int day);
        static QString lunarFestival(int month, int day);
    };
    
    #endif // DATE_H
    


    #include "date.h"
    
    #include <QDebug>
    
    
    #define T_D_YAER   1924 //  天干地支开始计算年月
    
    //每年春节对应的公历日期
    static const int springFestival[] = {
        130,217,206,                                // 1968,1969,1970
        127,215,203,123,211,131,218,207,128,216,    // 1971--1980
        205,125,213,202,220,209,219,217,206,127,    // 1981---1990
        215,204,123,210,131,219,207,128,216,205,    // 1991--2000
        124,212,201,122,209,129,218,207,126,214,    // 2001--2010
        203,123,210,131,219,208,128,216,205,125,    // 2011--2020                                       //2011--2020
        212,201,122,210,129,217,206,126,213,203,    // 2021--2030
        123,211,131,219,208,128,215,204,124,212     // 2031--2040
    };
    
    //16--18位表示闰几月,0--12位表示农历每月的数据,高位表示1月,低位表示12月(农历闰月就会多一个月)
    static const int  nLunarData[] = {
        461653,1386,2413,                                            // 1968,1969,1970
        330077,1197,2637,268877,3365,531109,2900,2922,398042,2395,   // 1971--1980
        1179,267415,2635,661067,1701,1748,398772,2742,2391,330031,   // 1981---1990
        1175,1611,200010,3749,527717,1452,2742,332397,2350,3222,     // 1991--2000
        268949,3402,3493,133973,1386,464219,605,2349,334123,2709,    // 2001--2010
        2890,267946,2773,592565,1210,2651,395863,1323,2707,265877,   // 2011--2020
        1706,2773,133557,1206,398510,2638,3366,335142,3411,1450,     // 2021 -- 2030
        200042,2413,723293,1197,2637,399947,3365,3410,334676,2906    // 2031 -- 2040
    };
    
    static const int chineseTwentyFourData[] = {
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87,     // 1970
        0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77,     // 1971
        0x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 1972
        0xA5,0xB5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0x87,     // 1973
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87,     // 1974
        0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0x77,     // 1975
        0x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x89,0x88,0x78,0x87,0x87,     // 1976
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 1977
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87,     // 1978
        0x96,0xB4,0x96,0xA6,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77,     // 1979
        0x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 1980
        0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x77,0x87,     // 1981
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87,     // 1982
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77,     // 1983
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87,     // 1984
        0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 1985
        0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87,     // 1986
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x79,0x78,0x69,0x78,0x87,     // 1987
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 1988
        0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87,     // 1989
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87,     // 1990
        0x95,0xB4,0x96,0xA5,0x86,0x97,0x88,0x78,0x78,0x69,0x78,0x87,     // 1991
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 1992
        0xA5,0xB3,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87,     // 1993
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87,     // 1994
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x76,0x78,0x69,0x78,0x87,     // 1995
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 1996
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 1997
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87,     // 1998
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87,     // 1999
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 2000
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 2001
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87,     // 2002
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87,     // 2003
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 2004
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 2005
        0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 2006
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87,     // 2007
        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x87,0x78,0x87,0x86,     // 2008
        0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 2009
        0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 2010
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87,     // 2011
        0x96,0xB4,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86,     // 2012
        0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87,     // 2013
        0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 2014
        0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87,     // 2015
        0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86,     // 2016
        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87,     // 2017
        0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 2018
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87,     // 2019
        0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86,     // 2020
        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 2021
        0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87,     // 2022
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87,     // 2023
        0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96,     // 2024
        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 2025
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 2026
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87,     // 2027
        0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96,     // 2028
        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 2029
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87,     // 2030
        0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87,     // 2031
        0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96,     // 2032
        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x86,     // 2033
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x78,0x88,0x78,0x87,0x87,     // 2034
        0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87,     // 2035
        0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96,     // 2036
        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     // 2037
        0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87      // 2038
    };
    
    static const char *s_pchDayName[] =  {
        ("*"),
        ("初一"), ("初二"), ("初三"), ("初四"), ("初五"),
        ("初六"), ("初七"), ("初八"), ("初九"), ("初十"),
        ("十一"), ("十二"), ("十三"), ("十四"), ("十五"),
        ("十六"), ("十七"), ("十八"), ("十九"), ("二十"),
        ("廿一"), ("廿二"), ("廿三"), ("廿四"), ("廿五"),
        ("廿六"), ("廿七"), ("廿八"), ("廿九"), ("三十")
    };
    
    /*农历月份名*/
    static const char *s_pchMonName[] = {
        ("*"),
        ("正月"), ("二月"), ("三月"), ("四月"),
        ("五月"), ("六月"), ("七月"), ("八月"),
        ("九月"), ("十月"), ("冬月"), ("腊月")
    };
    
    // 24节气
    static const char *s_pchSolarTerm[] = {
        ("小寒"), ("大寒"), ("立春"), ("雨水"), ("惊蛰"), ("春分"), ("清明"), ("谷雨"),
        ("立夏"), ("小满"), ("芒种"), ("夏至"), ("小暑"), ("大暑"), ("立秋"), ("处暑"),
        ("白露"), ("秋分"), ("寒露"), ("霜降"), ("立冬"), ("小雪"), ("大雪"), ("冬至")
    };
    
    
    // 天干算法
    static const char *s_pchTiangan[] = {
        ("甲"), ("乙"), ("丙"), ("丁"), ("戊"),
        ("己"), ("庚"), ("辛"), ("壬"), ("癸"),
    };
    
    // 动物属性
    static const char *s_pchAnimal[] = {
        ("鼠"), ("牛"), ("虎"), ("兔"), ("龙"), ("蛇"),
        ("马"), ("羊"), ("猴"), ("鸡"), ("狗"), ("猪"),
    };
    
    // 地址算法
    static const char *s_pchDizhi[] = {
        ("子"), ("丑"), ("寅"), ("卯"), ("辰"), ("巳"),
        ("午"), ("未"), ("申"), ("酉"), ("戌"), ("亥"),
    };
    
    /*公历每月前面的天数*/
    int monthAdd[] = {
        0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
    };
    
    
    Date::Date(QObject *parent) : QObject(parent)
    {
    
    }
    
    /**
     * @brief Date::getSpringFestivalMonth 获取当年春节是几月几日
     * @param year
     * @return
     */
    quint16 Date::getSpringFestivalDate(int year)
    {
        int nTemp = year - 1968;
        int springFestivalMonth = springFestival[nTemp] / 100;
        int springFestivalDay = springFestival[nTemp] % 100;
        qDebug() << springFestivalMonth << springFestivalDay;
    
        return (springFestivalMonth << 8) | springFestivalDay;
    }
    
    int Date::getFirstDayOfWeek(int year, int month)
    {
        int week = 0;
        // 获取当年1月1日是星期几
        week = (year + (year- 1) / 4 -(year - 1) / 100 + (year - 1) / 400) % 7;
        week += getTotalMonthDays(year, month);
        return week % 7;
    }
    
    int Date::getTotalMonthDays(int year, int month)
    {
        int nDays = 0;
        int nLoopDay = isLoopYaer(year) ? 1 : 0;
        switch (month) {
        case  1: nDays =   0;            break;
        case  2: nDays =  31;            break;
        case  3: nDays =  59 + nLoopDay; break;
        case  4: nDays =  90 + nLoopDay; break;
        case  5: nDays = 120 + nLoopDay; break;
        case  6: nDays = 151 + nLoopDay; break;
        case  7: nDays = 181 + nLoopDay; break;
        case  8: nDays = 212 + nLoopDay; break;
        case  9: nDays = 243 + nLoopDay; break;
        case 10: nDays = 273 + nLoopDay; break;
        case 11: nDays = 304 + nLoopDay; break;
        case 12: nDays = 334 + nLoopDay; break;
        default: nDays = 0; break;
        }
        return nDays;
    }
    
    int Date::getMonthDays(int year, int month)
    {
        int nDays = 0;
        int nLoopDay = isLoopYaer(year) ? 1 : 0;
        switch (month) {
        case  1: nDays = 31;            break;
        case  2: nDays = 28 + nLoopDay; break;
        case  3: nDays = 31;            break;
        case  4: nDays = 30;            break;
        case  5: nDays = 31;            break;
        case  6: nDays = 30;            break;
        case  7: nDays = 31;            break;
        case  8: nDays = 31;            break;
        case  9: nDays = 30;            break;
        case 10: nDays = 31;            break;
        case 11: nDays = 30;            break;
        case 12: nDays = 31;            break;
        default: nDays = 30;            break;
        }
    
        return nDays;
    }
    
    // 判断是否是闰年
    bool Date::isLoopYaer(int year)
    {
        return (((0 == (year % 4)) && (0 != (year % 100))) || (0 == (year % 400)));
    }
    
    /**
     * @brief Date::getLunarDate 计算农历
     * @param year  年
     * @param month 月
     * @param day 日
     * @return
     */
    QString Date::getLunarDate (int year, int month, int day){
        int nTheDate,nIsEnd,nMonTemp,k,n,nBit;
        // 先获取公历节日
        QString strDate = holiday(month, day);
        // 计算24节气
        QString strSolarTerms = solarTerms(year, month, day);
    
        /*现在计算农历:获得当年春节的公历日期(比如:2015年春节日期为(2月19日)),
                以此为分界点,2.19前面的农历是2014年农历(用2014年农历数据来计算),
                2.19以及之后的日期,农历为2015年农历(用2015年农历数据来计算)。*/
        nMonTemp = year - 1968;
        int springFestivalMonth = springFestival[nMonTemp] / 100;
        int springFestivalDaty = springFestival[nMonTemp] % 100;
    
        if(month < springFestivalMonth )
        {
            nMonTemp--;
            nTheDate = 365 * 1 + day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
    
            if((!(year % 4)) && (month > 2))
                nTheDate = nTheDate + 1;
    
            if((!((year - 1) % 4)))
                nTheDate = nTheDate + 1;
        }
        else if (month == springFestivalMonth)
        {
            if (day < springFestivalDaty) {
                nMonTemp--;
                nTheDate = 365 * 1 + day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
    
                if((!(year % 4)) && (month > 2))
                    nTheDate = nTheDate + 1;
    
                if((!((year-1) % 4)))
                    nTheDate = nTheDate + 1;
            }
            else {
                nTheDate = day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
    
                if((!(year % 4)) && (month > 2))
                    nTheDate = nTheDate + 1;
            }
        }else{
            nTheDate = day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
            if((!(year % 4)) && (month > 2))
                nTheDate = nTheDate + 1;
        }
        /*--计算农历天干、地支、月、日---*/
        nIsEnd = 0;
    
        while(nIsEnd != 1)  {
            if(nLunarData[nMonTemp] < 4095)
                k = 11;
            else
                k = 12;
            n = k;
            while(n >= 0)   {
                // 获取wNongliData(m)的第n个二进制位的值
                nBit = nLunarData[nMonTemp];
    
                nBit = nBit >> n;
                nBit = nBit % 2;
                if (nTheDate <= (29 + nBit))    {
                    nIsEnd = 1;
                    break;
                }
    
                nTheDate = nTheDate - 29 - nBit;
                n = n - 1;
            }
    
            if(nIsEnd)
                break;
    
            nMonTemp = nMonTemp + 1;
        }
    
        // 农历的年月日
        year = 1969 + nMonTemp -1;
        month = k - n + 1;
        day = nTheDate;
    
        if (k == 12)  {
            if (month == (nLunarData[nMonTemp] / 65536) + 1)
                month = 1 - month;
            else if (month > (nLunarData[nMonTemp] / 65536) + 1)
                month = month - 1;
        }
    
        // 显示装换的农历
        // only day == 1 ,return month name
        if (1 == day) {
            if(month < 1){
                strDate = "闰" + tr(s_pchMonName[month * -1]);
                return strDate;
            }
    
            // 公历节日
            if ("" != strDate) return strDate;
    
            // 计算农历节日
            strDate = lunarFestival(month, day);
    
            // 如果有节日,直接显示
            if ("" == strDate) {
                // 如果当天不是24节气,显示农历日子
                strDate = strSolarTerms;
                if ("" == strDate) {
                    strDate = tr(s_pchMonName[month]);
                }
            }
    
        } else {
            // 公历节日
            if ("" != strDate) return strDate;
    
            // 计算农历节日
            strDate = lunarFestival(month, day);
            // 如果有节日,直接显示
            if ("" == strDate) {
                // 如果当天不是24节气,显示农历日子
                strDate = strSolarTerms;
                if ("" == strDate) {
                    strDate = tr(s_pchDayName[day]);
                }
            }
        }
    
        return strDate;
    }
    
    /**
     * @brief Date::getLunarMonAndDay 响应点击时的农历显示
     * @param year
     * @param month
     * @param day
     * @return
     */
    QString Date::getLunarMonAndDay(int year, int month, int day)
    {
        int nTheDate, nIsEnd, nMonTemp, k, n, nBit;
        QString strDate = "";
        /*现在计算农历:获得当年春节的公历日期(比如:2015年春节日期为(2月19日)),
                以此为分界点,2.19前面的农历是2014年农历(用2014年农历数据来计算),
                2.19以及之后的日期,农历为2015年农历(用2015年农历数据来计算)。*/
        nMonTemp = year - 1968;
        int springFestivalMonth = springFestival[nMonTemp] / 100;
        int springFestivalDaty = springFestival[nMonTemp] % 100;
    
        if(month < springFestivalMonth )
        {
            nMonTemp--;
            nTheDate = 365 * 1 + day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
    
            if((!(year % 4)) && (month > 2))
                nTheDate = nTheDate + 1;
    
            if((!((year - 1) % 4)))
                nTheDate = nTheDate + 1;
        }
        else if (month == springFestivalMonth)
        {
            if (day < springFestivalDaty) {
                nMonTemp--;
                nTheDate = 365 * 1 + day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
    
                if((!(year % 4)) && (month > 2))
                    nTheDate = nTheDate + 1;
    
                if((!((year-1) % 4)))
                    nTheDate = nTheDate + 1;
            }
            else {
                nTheDate = day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
    
                if((!(year % 4)) && (month > 2))
                    nTheDate = nTheDate + 1;
            }
        }else{
            nTheDate = day + monthAdd[month - 1] - 31 * ((springFestival[nMonTemp] / 100) - 1) - springFestival[nMonTemp] % 100 + 1;
            if((!(year % 4)) && (month > 2))
                nTheDate = nTheDate + 1;
        }
        /*--计算农历天干、地支、月、日---*/
        nIsEnd = 0;
    
        while(nIsEnd != 1)  {
            if(nLunarData[nMonTemp] < 4095)
                k = 11;
            else
                k = 12;
            n = k;
            while(n >= 0)   {
                // 获取wNongliData(m)的第n个二进制位的值
                nBit = nLunarData[nMonTemp];
    
                nBit = nBit >> n;
                nBit = nBit % 2;
                if (nTheDate <= (29 + nBit))    {
                    nIsEnd = 1;
                    break;
                }
    
                nTheDate = nTheDate - 29 - nBit;
                n = n - 1;
            }
    
            if(nIsEnd)
                break;
    
            nMonTemp = nMonTemp + 1;
        }
    
        // 农历的年月日
        year = 1969 + nMonTemp -1;
        month = k - n + 1;
        day = nTheDate;
    
        if (k == 12)  {
            if (month == (nLunarData[nMonTemp] / 65536) + 1)
                month = 1 - month;
            else if (month > (nLunarData[nMonTemp] / 65536) + 1)
                month = month - 1;
        }
    
        // 显示装换的农历
        // only day == 1 ,return month name
        if (1 == day) {
            if (month < 1){
                strDate = tr("闰") + tr(s_pchMonName[month * -1]);
                return strDate;
            }
    
            strDate = tr(s_pchMonName[month]);
    
        } else {
            strDate = tr(s_pchMonName[month]) + tr(s_pchDayName[day]);
        }
    
        return strDate;
    }
    
    /**
     * @brief Date::getLunarTime  计算今年是什么年如 :甲子年
     * @param year
     * @return
     */
    QString Date::getLunarTime(int year)
    {
        int ntemp = 0;
        // 农历时辰
        QString strTime = "";
        if (year > T_D_YAER) {
            ntemp = year - T_D_YAER;
            strTime.append(tr(s_pchTiangan[ntemp % 10]));
            strTime.append(tr(s_pchDizhi[ntemp % 12]));
            strTime.append(tr(s_pchAnimal[ntemp % 12]));
            strTime.append(tr("年"));
        }
    
        return strTime;
    }
    
    
    /**
     * @brief Date::holiday 公历假日
     * @param month
     * @param day
     * @return
     */
    QString Date::holiday(int month, int day)
    {
        int temp = (month << 8) | day;
        QString strHoliday = "";
        switch (temp) {
        case 0x0101: strHoliday = tr("元旦");  break;
        case 0x020E: strHoliday = tr("情人节"); break;
        case 0x0308: strHoliday = tr("妇女节"); break;
        case 0x0401: strHoliday = tr("愚人节"); break;
        case 0x0501: strHoliday = tr("劳动节"); break;
        case 0x0504: strHoliday = tr("青年节"); break;
        case 0x0601: strHoliday = tr("儿童节"); break;
        case 0x0701: strHoliday = tr("建党节"); break;
        case 0x0801: strHoliday = tr("建军节"); break;
        case 0x090A: strHoliday = tr("教师节"); break;
        case 0x0A01: strHoliday = tr("国庆节"); break;
        case 0x0C18: strHoliday = tr("圣诞节"); break;
        default: break;
        }
    
        return strHoliday;
    }
    
    /**
     * @brief Date::chineseTwentyFourDay 计算24节气
     * @param year
     * @param month
     * @param day
     * @return
     */
    QString Date::solarTerms(int year, int month, int day){
        int dayTemp = 0;
        int index = (year - 1970) * 12 + month - 1;
    
        if (day < 15) {
            dayTemp = 15 - day;
            if((chineseTwentyFourData[index] >> 4) == dayTemp)
                return tr(s_pchSolarTerm[2 * (month - 1)]);
            else
                return "";
    
        } else if (day > 15) {
            dayTemp = day - 15;
            if((chineseTwentyFourData[index] & 0x0f) == dayTemp)
                return tr(s_pchSolarTerm[2 * (month - 1) + 1]);
        }
    
        return "";
    }
    
    /**
     * @brief Date::lunarFestival 农历春节节日
     * @param month
     * @param day
     * @return 节日
     */
    QString Date::lunarFestival(int month, int day){
        int temp = (month << 8) | day;
        QString strFestival = "";
        switch (temp) {
        case 0x0101: strFestival = tr("春节");  break;
        case 0x010F: strFestival = tr("元宵节"); break;
        case 0x0202: strFestival = tr("龙抬头"); break;
        case 0x0505: strFestival = tr("端午节"); break;
        case 0x0707: strFestival = tr("七夕节"); break;
        case 0x080F: strFestival = tr("中秋节"); break;
        case 0x0909: strFestival = tr("重阳节"); break;
        case 0x0C08: strFestival = tr("腊八节"); break;
        default: break;
        }
    
        return strFestival;
    }
    



    代码里面我还添加了日程管理,不过未写完,留个位置在那里,以后心情好了在完善,至此核心代码已经完成。


    给个源代码的下载地址吧:

    http://download.csdn.net/detail/nigoole/9492904


    展开全文
  • 带农历天干地支的jQuery日历

    热门讨论 2012-12-18 14:53:52
    带农历天干地支的日历插件、可以直接拿来使用的!
  • 带有农历日历(QT版本1752-2100)(转)[@more@]简短描述:一个用qt 4.1编写的日历程序,支持农历查询.支持多个平台。todo 等待kde4发布,写成kde4的小程序,可以放到面板上.bug fix.Chan...
  • 转:有带农历日历代码

    千次阅读 2004-12-19 21:50:00
    bsYear="农历"+Yn[iyear]; bsYear2=Mn[miy]+Dn[dayim-1]; if (ss>=Ys[7]||ss[0]) bsYear=Yn[7]; function time(){ document.write("; font-family:Tahoma;background:infobackground' cellspacing='0' width='90' ...
  • 完整的带农历日历

    2007-01-11 09:25:00
    中国农历开始 --> SCRIPT language=javascript> var lunarInfo=new Array( 0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2, 0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,...
  • 2、日历带有农历 3、后台可以获取开始时间和结束时间 4、日期事件里面可以添加图标 等等 。。。。 代码访问fullCalendar.jsp ---------------------------代码讲解,主调用fullCalendar.jsp-------- ...
  • 在网上找了许多大牛做的农历日历,但是不是不符合项目中的要求,就是本身就问题Bug ,把大牛门的做日历看了n遍 自己又改造了一遍得到了这个:随后日历又要做个自适应的长宽,又在js中改造代码。。。。。。 也...
  • android日历农历

    热门讨论 2011-09-01 15:51:43
    activity目录下: CalendarActivity.java 主要的Activity ChineseCalendarGB.java 农历处理类 Constant.java 常量
  • -- 中国农历开始 --> <SCRIPT language=JavaScript> <!-- var lunarInfo=new Array( 0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2, 0x04ae0,0x0a5b6,...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,248
精华内容 499
关键字:

下载带有农历的日历