后台代码:

#region 生成某年某月的日历,代码是去掉<table>标记的部分/// <summary>
/// 取某天的农历日期
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
/// <param name="day"></param>
/// <returns></returns>
public static string GetNongliRiqi(int year, int month, int day)
{
DateTime m_Date = new DateTime(year, month, day);
int cnd,cnm,icnm;
ChineseLunisolarCalendar cnCalendar = new ChineseLunisolarCalendar();
cnd = cnCalendar.GetDayOfMonth(m_Date);
cnm = cnCalendar.GetMonth(m_Date);
icnm = cnCalendar.GetLeapMonth(cnCalendar.GetYear(m_Date));
string txcns = "";
//格式化月份显示
string[] cnMonth ={ "", "正月", "二月", "三月", "四月", "五月", "六月"
, "七月", "八月", "九月", "十月", "十一月", "十二月", "十二月" };
if (icnm > 0)
{
//for (int i = icnm + 1; i < 13; i++) cnMonth[i] = cnMonth[i - 1];
for (int i = 12; i >= icnm; i--) cnMonth[i] = cnMonth[i - 1];
cnMonth[icnm] = "闰" + cnMonth[icnm];
}
txcns += cnMonth[cnm];
string[] cnDay ={ "", "初一", "初二", "初三", "初四", "初五", "初六", "初七"
, "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六"
, "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五"
, "廿六", "廿七", "廿八", "廿九", "三十" };
txcns += cnDay[cnd];
return txcns;
}
/// <summary>
/// 生成某年某月的日历,代码是去掉<table>标记的部分
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
/// <returns></returns>
public static string GetRlStr(int year, int month)
{
StringBuilder sb = new StringBuilder();
DateTime today = DbHelper.GetCurrentTime();//取当前天,当前天以前的日历应该是不可点的
DateTime dtime = new DateTime(year, month, 1);
int firweek = Convert.ToInt32(dtime.DayOfWeek);//看这个月的最后一天是周几
int endday = GetTheEndDay(dtime);//取这年这月的最后一天
DateTime etime = new DateTime(year, month, endday);
int eweek = Convert.ToInt32(etime.DayOfWeek);//取这个月最后一天的星期
int row = 5;
int total = endday + firweek;
if (total % 7 == 0)
{
row = total / 7;
}
else
{
row = total / 7 + 1;
}
int day = 1;
for (int i = 0; i < row; i++)
{
sb.Append("<tr>");
if (i == 0)
{
int k = 0;
for (k = 0; k < firweek; k++)
{
sb.Append("<td class=\"dis\"></td>");
}
//将第一行补充完整
for (int t = k; t < 7; t++)
{
string tdclass = " class=\"can srl\"";
string clstr = " class=\"canen\"";
DateTime ntime = new DateTime(year, month, day);
if (today > ntime)
{
tdclass = " class=\"noc\"";
clstr = "";
}
string nl = GetNongliRiqi(year, month, day);
sb.Append("<td" + tdclass + "><div class=\"rq\">" + day + "</div><div" + clstr + ">" + "</div><div class=\"nl\">" + nl + "</div></td>");
day++;//天数加一
}
}
else if (i == row-1)
{
for (int k = 0; k <= eweek; k++)
{
string tdclass = " class=\"can srl\"";
string clstr = " class=\"canen\"";
DateTime ntime = new DateTime(year, month, day);
if (today > ntime)
{
tdclass = " class=\"noc\"";
clstr = "";
}
string nl = GetNongliRiqi(year, month, day);
sb.Append("<td" + tdclass + "><div class=\"rq\">" + day + "</div><div" + clstr + ">" + "</div><div class=\"nl\">" + nl + "</div></td>");
day++;//天数加一
}
//将最后一行补全
for (int k = eweek+1; k < 7; k++)
{
sb.Append("<td class=\"dis\"></td>");
}
}
else
{
//中间行都是满的
for (int k = 0; k < 7; k++)
{
string tdclass = " class=\"can srl\"";
string clstr = " class=\"canen\"";
DateTime ntime = new DateTime(year, month, day);
if (today > ntime)
{
tdclass = " class=\"noc\"";
clstr = "";
}
string nl = GetNongliRiqi(year, month, day);
sb.Append("<td" + tdclass + "><div class=\"rq\">" + day + "</div><div" + clstr + ">" + "</div><div class=\"nl\">" + nl + "</div></td>");
day++;
}
}
sb.Append("</tr>");
}
return sb.ToString();
}#endregion

前台:

<table width="100%" cellpadding="0" cellspacing="0" class="mytab" id="rltab"><tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr><%=BaseMethod.GetRlStr(2014,3)%></table>

样式:

#rltab td
{
height:60px;
position:relative;
}
#rltab td.dis
{
cursor:not-allowed;
background:#acacac;
}
#rltab td.noc
{
cursor:not-allowed;
background:#bbb;
}
#rltab td.can
{
cursor:pointer;
}
#rltab td .rq
{
position:absolute;
right:0px;
width:20px;
height:20px;
top:0px;
text-align:center;
}
#rltab td .nl
{
position:absolute;
bottom:0px;
height:20px;
left:0px;
color:#aaa;
padding-left:5px;
}
#rltab td .canen
{
position:absolute;
top:20px;
height:35px;
left:0px;
width:100%;
z-index:3;
text-align:center;
}

效果如图:

.net生成日历(带农历)相关推荐

  1. 带节日和农历的js日历 带农历的脚本:

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  2. 2021年1--3月日历带农历天干地支

  3. 日历组件带农历及事件标记,绑定点击事件

    前段时间需要做一个课程日历的记事,还需要带农历,网上查了一下现有的日历带农历的代码分享,整合了一下自己的事件业务逻辑,最终做了这么一个日历组件(农历使用紫金山天文台农历编码1921-2023,有没有大 ...

  4. Java自动生成日历,移除节假日和周六日

    Java生成日历,排除周六日以及法定节假日 一.生成简单日历,排除周六日和法定节假日 二.生成日历,农历转换,排除节假日 一.生成简单的日历 1.设置某年的开始时间和结束时间,例如:2021-01-0 ...

  5. win7日历加入农历_还是农历更亲切,春节制作一个带农历的日历,欢欢喜喜过新年...

    2019带农历的日历 上图是用iSee图片专家制成的2019年2月份的台历,看上去就很豪华的样子,这个日历让我花费了不少的心血.其实,应该很多人都听说过iSee图片专家这个软件,它是一款功能十分全面的 ...

  6. 基于51单片机的DS12C887电子钟万年历带农历温度

    基于51单片机的DS12C887电子钟万年历( proteus仿真+程序+讲解视频) 仿真图proteus 7.8及以上 程序编译器:keil 4/keil 5 编程语言:C语言 设计编号:S0028 ...

  7. google日历的农历循环提醒

    参见:http://www.zh001.com/viewthread.php?tid=460 使用 Google 日历,可以轻松管理日常生活中的各种重要事项.添加活动和发送邀请,与亲朋好友共享日程表, ...

  8. 自定义IT女神节日历与农历

    今天是女神节,来一篇日历显示当前日期与农历,以及显示特殊节日 一.新建窗体应用程序CustomCalendarDemo 将默认的Form1重命名为FormCustomDate,窗体FormCustom ...

  9. csdn论坛中关于在word中生成日历的问题的解答

    原贴地址http://community.csdn.net/Expert/topic/4304/4304006.xml?temp=.9009668 因为代码比较长所以帖到blog中来,也欢迎大家提意见 ...

  10. linux万年历,GDI+带农历的万年历(周历)之制作

    今天在网上无意中搜索到"Vista风格日历控件"().下载之后发现,略有BUG,于是进行改进.无意中,制作出来带农历的万年历(周历版). 运行如下图: 主要的改进在: // frm ...

最新文章

  1. 送你一份 Kubernetes 实用命令速查表
  2. 计算机解题报告,计算机题目33题(附带题解)精选.doc
  3. 算法 --- [队列结构]二叉树的层次遍历
  4. 文档在线签名_为什么需要为文档和合同切换到在线签名
  5. Hadoop平台优化综述(一)
  6. c++ 函数当参数传参,类函数当参数传参,匿名函数当参数传参,function<void()>
  7. java字符串_Java字符串
  8. Android 微信支付
  9. 单片机实验(流水灯)(c语言程序),51单片机c语言_单片机流水灯c语言程序_单片机c语言入门...
  10. 让 orangepi 用上Btsync(资源分享工具)好资源不怕和谐!
  11. 中医预约挂号系统,代煎取药功能原来这样用?
  12. oracle入门教程+视频教程
  13. 22. SCHEMA_PRIVILEGES
  14. 微信公号DIY:训练微信聊天机器人公号变身图片上传工具
  15. 计算机病毒防治教案,计算机病毒与防治教案
  16. virtualbox 菜单栏不见了---如何调出来
  17. [lintcode]879. 输出赛程表
  18. 【CSS】笔记2-复合选择器、显示模式、背景
  19. 【论文阅读】2021中国法研杯司法考试数据集研究(CAIL2021)
  20. 法坤老师:百度网盘密道转存12.0群文件自动转存发布咯

热门文章

  1. 2018年度中国电池行业百强企业名单发布
  2. 人工智能训练师AIT的工作是什么呢
  3. win10公司内网连接失败解决方案大全100%解决(非翻墙)
  4. 登录注册中的验证码倒计时
  5. 三角矩阵上三角列优先压缩存储---加法、减法、乘法、转置、秩、行列式值、伴随矩阵、逆
  6. android 简易闹钟,android简易小闹钟
  7. 开启E680i的虚拟内存
  8. 物联网安全业务去哪里找?——拓展认知,增强技术,落地应用
  9. vue 页面设置meta标签
  10. 谷歌通过Chrome简化登录安卓密码支持