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 ...
随机推荐
- 使用Subversion进行源代码管理(二):创建和发布版本库[转]
原文出处: http://www.blogjava.net/youxia/archive/2007/10/23/155372.html 我的上一篇随笔讲了怎么使用Subversion客户端去连接服务器 ...
- 剑指Offer - 九度1509 - 树中两个结点的最低公共祖先
剑指Offer - 九度1509 - 树中两个结点的最低公共祖先2014-02-07 01:04 题目描述: 给定一棵树,同时给出树中的两个结点,求它们的最低公共祖先. 输入: 输入可能包含多个测试样 ...
- 编译gearman提示缺少boost
编译german时提示缺少boost: checking for boostlib >= 1.39... configure: We could not detect the boost lib ...
- 【Text Justification】cpp
题目: Given an array of words and a length L, format the text such that each line has exactly L charac ...
- python - web自动化测试 - 元素操作 - 定位
# -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: find_ele.py @ide: PyCharm Community ...
- Python程序执行时的不同电脑路径不同问题
原因:因代码转移时项目路径发生了变化,导致解释器无法找到对应路径,是的程序无法正常执行 需求: 1.我希望代码能在不同的电脑下,不必修改源代码就能正常执行(所需模块已安装的前提下) 2.我希望代码在命 ...
- Mysql忘记root密码怎么办?(已解决)
为了写这篇文档,假装一下忘记密码!!!! 首先我数据库是正常的,可以使用. root@localhost:~# mysql -uroot -p mysql> mysql> show dat ...
- Python学习-前台开发-ajax操作
概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用 一个简单操作需要 ...
- 使用dib element proliant-tools制作deploy image
element proliant-tools会在ipa ramdisk中安装一个rpm包hpssacli(HP的RAID管理工具),和一个python module proliantutils(里面P ...
- python /usr/bin/python^M: bad interpreter: No such file
今天在WingIDE下写了个脚本,传到服务器执行后提示: -bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No suc ...