C# 获取农历日期
//C# 获取农历日期 ///<summary>
/// 实例化一个 ChineseLunisolarCalendar
///</summary>
private static ChineseLunisolarCalendar ChineseCalendar =new ChineseLunisolarCalendar();
///<summary>
/// 十天干
///</summary>
private static string[] tg = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
///<summary>
/// 十二地支
///</summary>
private static string[] dz = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
///<summary>
/// 十二生肖
///</summary>
private static string[] sx = { "鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
///<summary>
/// 返回农历天干地支年
///</summary>
///<param name="year">农历年</param>
///<return s></return s>
public static string GetLunisolarYear(int year)
{
if (year >)
{
int tgIndex = (year -) %;
int dzIndex = (year -) %;
return string.Concat(tg[tgIndex], dz[dzIndex], "[", sx[dzIndex], "]");
}
throw new ArgumentOutOfRangeException("无效的年份!");
}
///<summary>
/// 农历月
///</summary>
///<return s></return s>
private static string[] months = { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)" };
///<summary>
/// 农历日
///</summary>
private static string[] days1 = { "初", "十", "廿", "三" };
///<summary>
/// 农历日
///</summary>
private static string[] days = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
///<summary>
/// 返回农历月
///</summary>
///<param name="month">月份</param>
///<return s></return s>
public static string GetLunisolarMonth(int month)
{
if (month < && month >)
{
return months[month -];
}
throw new ArgumentOutOfRangeException("无效的月份!");
}
///<summary>
/// 返回农历日
///</summary>
///<param name="day">天</param>
///<return s></return s>
public static string GetLunisolarDay(int day)
{
if (day > && day <)
{
if (day != && day !=)
{
return string.Concat(days1[(day -) /], days[(day -) %]);
}
else
{
return string.Concat(days[(day -) /], days1[]);
}
}
throw new ArgumentOutOfRangeException("无效的日!");
}
///<summary>
/// 根据公历获取农历日期
///</summary>
///<param name="datetime">公历日期</param>
///<return s></return s>
public static string GetChineseDateTime(DateTime datetime)
{
int year = ChineseCalendar.GetYear(datetime);
int month = ChineseCalendar.GetMonth(datetime);
int day = ChineseCalendar.GetDayOfMonth(datetime);
//获取闰月, 0 则表示没有闰月
int leapMonth = ChineseCalendar.GetLeapMonth(year);
bool isleap =false;
if (leapMonth >)
{
if (leapMonth == month)
{
//闰月
isleap =true;
month--;
}
else if (month > leapMonth)
{
month--;
}
}
return string.Concat(GetLunisolarYear(year), "年", isleap ?"闰" : string.Empty, GetLunisolarMonth(month), "月", GetLunisolarDay(day));
}
C# 获取农历日期的更多相关文章
- js 根据年月获取当月有多少天_js获取农历日期_及Js其它常用有用函数
//根据年月获取当月有多少天 function getDaysInMonth(year, month) { debugger; //parseInt(number,type)这个函数后面如果不跟第2个 ...
- js获取农历日期【转】
var CalendarData=new Array(100); var madd=new Array(12); var tgString="甲乙丙丁戊己庚辛壬癸"; var dz ...
- C#获取农历的日期(转)
//C# 获取农历日期 ///<summary> /// 实例化一个 ChineseLunisolarCalendar ///</summary> private static ...
- WindowsPhone 在 根据公历 获取月球日期数据
WindowsPhone 在 根据公历 获取月球日期数据 WindowsPhone 在 它们的定义 类,根据公历 获取月球日期数据 using System; using System.Collect ...
- ChineseLunisolarCalendar 农历日期
#region 农历日期 static ChineseLunisolarCalendar cCalendar = new ChineseLunisolarCalendar(); /// <sum ...
- iOS 获取公历、农历日期的年月日
iOS 获取公历.农历日期的年月日 介绍三种方法获取 Date (NSDate) 的年月日. 用 date 表示当前日期.测试日期为公历 2017 年 2 月 5 日,农历丁酉年,鸡年,正月初九. l ...
- js获取中国日期-农历
/* var bsYear; var bsDate; var bsWeek; var arrLen=8; //数组长度 var sValue=0; //当年的秒数 var dayiy=0; //当年第 ...
- 利用Javascript获取当前日期的农历日期
来源:http://www.ido321.com/926.html JavaScript代码 1: /*设置农历日期*/ 2: var CalendarData=new Array(100); 3: ...
- atitit.农历的公式与原理以及农历日期运算
atitit.农历的公式与原理以及农历日期运算 1. 农历的概述1 2. 如何在电脑程序里面计算农历??1 3. 农历的公式2 4. 获取当日农历日历3 5. 历史日期公式加查表才能得到精确日期3 6 ...
随机推荐
- 微信里经常看到的滑动翻页效果,slide
上个星期我们的产品姐姐让我帮她写个微信里经常看到的滑动翻页效果,今天抽空写了3个小demo(只写了webkit需要chrome模拟手机看 开启touch事件), 故此写个随笔. 1.demo1,整个大 ...
- Python IO关于mode参数的问题
关于open()的mode参数: 'r':读 'w':写 'a':追加 'r+' == r+w(可读可写,文件若不存在就报错(IOError)) 'w+' == w+r(可读可写,文件若不存在就创建) ...
- 小红帽安装centos的yum的一些坑!
[root@localhost ~]# lsanaconda-ks.cfg yum-3.4.3-158.el7.centos.noarch.rpm yum-updateonboot-1.1.31-45 ...
- Mecanim动画
1.基础 现在Animation编辑器给个模型设计一个动画,都会自动为此模型加上Animator组件,并产生一个controller后缀的控制器和一个相关的anim后缀的动画剪辑, unity根据An ...
- Oz 创建CentOS7镜像
参考链接: https://github.com/clalancette/oz/wiki/Oz-template-description-language https://github.com/cla ...
- juqery基本选择器和层级选择器
1.基本选择器,主要通过标签名称,样式,id等选择标签,如下代码是简单的使用 (1)根据标签或者样式筛选 <!DOCTYPE html> <html lang="en&qu ...
- HDU 4661 Message Passing ( 树DP + 推公式 )
参考了: http://www.cnblogs.com/zhsl/archive/2013/08/10/3250755.html http://blog.csdn.net/chaobaimingtia ...
- 对象内存 (扩展 Data Structure Alignment)
对于一个class object来说,我们需要多少内存才能表现出来,大致分为3类,这里在前面文章有内存图 (1)非静态数据成员的综合大小,这也符合了c++对象模型的结构 (2)填充字节,就是我们所说的 ...
- 【bzoj3669】[Noi2014]魔法森林 Kruskal+LCT
原文地址:http://www.cnblogs.com/GXZlegend/p/6797748.html 题目描述 为了得到书法大家的真传,小E同学下定决心去拜访住在魔法森林中的隐士.魔法森林可以被看 ...
- [2018-9-4T2]探索黑暗dark
题目大意:有一棵树,第$i$个点的点权为$s_i(s_1>0)$.初始有每个点都是亮的.$m$次修改,每次改变一个点的亮暗,回答包含$1$的全亮的连通块中点权和最大的连通块的和的值. 题解:正解 ...