没有合适的资源?快使用搜索试试~ 我知道了~
主要介绍了C#实现带阴历显示的日期代码,可以显示节假日及农历日期,在C#项目开发中非常具有实用价值,需要的朋友可以参考下
资源推荐
资源详情
资源评论
C#实现带阴历显示的日期代码实现带阴历显示的日期代码
主要介绍了C#实现带阴历显示的日期代码,可以显示节假日及农历日期,在C#项目开发中非常具有实用价值,需要
的朋友可以参考下
本文实例讲述了C#实现带阴历显示的日期代码,分享给大家供大家参考。具体方法如下:
这是一个用于酒店预定功能的带日期控件,类似去哪网酒店预定,由于需要设置节假日不同时期内的价格,因此需要自己写个
时间控件。在此分享下写时间控件过程中用到的农历显示类。
复制代码 代码如下:
public class CnCalendar
{
static ChineseLunisolarCalendar cCalendar = new ChineseLunisolarCalendar();
public static string GetChineseDateTime(DateTime datetime)
{
string strDate = datetime.Month + "月" + datetime.Day + "日";
int lyear = cCalendar.GetYear(datetime);
int lmonth = cCalendar.GetMonth(datetime);
int lday = cCalendar.GetDayOfMonth(datetime);
//获取闰月, 0 则表示没有闰月
int leapMonth = cCalendar.GetLeapMonth(lyear);
bool isleap = false;
if (leapMonth > 0)
{
if (leapMonth == lmonth)
{
//闰月
isleap = true;
lmonth--;
}
else if (lmonth > leapMonth)
{
lmonth--;
}
}
if (strDate == "1月1日")
{
return "<em class='calendarNLJieri'>元旦</em>";
}
else if (strDate == "2月14日")
{
return "<em class='calendarNLJieri'>情人节</em>";
}
else if (strDate == "3月8日")
{
return "<em class='calendarNLJieri'>妇女节</em>";
}
else if (strDate == "3月12日")
{
return "<em class='calendarNLJieri'>植树节</em>";
}
else if (strDate == "4月1日")
{
return "<em class='calendarNLJieri'>愚人节</em>";
}
else if (strDate == "5月1日")
{
return "<em class='calendarNLJieri'>劳动节</em>";
}
else if (strDate == "5月4日")
{
return "<em class='calendarNLJieri'>青年节</em>";
}
else if (strDate == "6月1日")
{
return "<em class='calendarNLJieri'>儿童节</em>";
资源评论
weixin_38592611
- 粉丝: 7
- 资源: 879
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功