You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1371 lines
41 KiB
1371 lines
41 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace QM.Common
|
|
{
|
|
///<summary>
|
|
/// 模块编号:QM.Common.FuncDate
|
|
/// 作 用:共通日期处理函数
|
|
/// 作 者:
|
|
/// 编写日期:2014-05-05
|
|
///</summary>
|
|
|
|
public class FuncDate
|
|
{
|
|
#region 属性
|
|
/// <summary>
|
|
/// 起始年
|
|
/// </summary>
|
|
private const ushort START_YEAR = 1901;
|
|
|
|
/// <summary>
|
|
/// 结束年
|
|
/// </summary>
|
|
private const ushort END_YEAR = 2050;
|
|
|
|
/// <summary>
|
|
/// 星座
|
|
/// </summary>
|
|
private static string[] ConstellationName = {
|
|
"白羊座", "金牛座", "双子座",
|
|
|
|
"巨蟹座", "狮子座", "处女座",
|
|
|
|
"天秤座", "天蝎座", "射手座",
|
|
|
|
"摩羯座", "水瓶座", "双鱼座" };
|
|
|
|
/// <summary>
|
|
/// 节气
|
|
/// </summary>
|
|
private static string[] LunarHolDayName = {
|
|
"小寒", "大寒", "立春", "雨水",
|
|
|
|
"惊蛰", "春分", "清明", "谷雨",
|
|
|
|
"立夏", "小满", "芒种", "夏至",
|
|
|
|
"小暑", "大暑", "立秋", "处暑",
|
|
|
|
"白露", "秋分", "寒露", "霜降",
|
|
|
|
"立冬", "小雪", "大雪", "冬至" };
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 数组gLunarDay存入阴历1901年到2100年每年中的月天数信息,
|
|
/// 阴历每月只能是29或30天,一年用12(或13)个二进制位表示,对应位为1表30天,否则为29天
|
|
/// </summary>
|
|
private static int[] gLunarMonthDay = {
|
|
//测试数据只有1901.1.1 --2050.12.31
|
|
|
|
0x4ae0, 0xa570, 0x5268, 0xd260, 0xd950, 0x6aa8, 0x56a0, 0x9ad0, 0x4ae8, 0x4ae0, //1910
|
|
|
|
0xa4d8, 0xa4d0, 0xd250, 0xd548, 0xb550, 0x56a0, 0x96d0, 0x95b0, 0x49b8, 0x49b0, //1920
|
|
|
|
0xa4b0, 0xb258, 0x6a50, 0x6d40, 0xada8, 0x2b60, 0x9570, 0x4978, 0x4970, 0x64b0, //1930
|
|
|
|
0xd4a0, 0xea50, 0x6d48, 0x5ad0, 0x2b60, 0x9370, 0x92e0, 0xc968, 0xc950, 0xd4a0, //1940
|
|
|
|
0xda50, 0xb550, 0x56a0, 0xaad8, 0x25d0, 0x92d0, 0xc958, 0xa950, 0xb4a8, 0x6ca0, //1950
|
|
|
|
0xb550, 0x55a8, 0x4da0, 0xa5b0, 0x52b8, 0x52b0, 0xa950, 0xe950, 0x6aa0, 0xad50, //1960
|
|
|
|
0xab50, 0x4b60, 0xa570, 0xa570, 0x5260, 0xe930, 0xd950, 0x5aa8, 0x56a0, 0x96d0, //1970
|
|
|
|
0x4ae8, 0x4ad0, 0xa4d0, 0xd268, 0xd250, 0xd528, 0xb540, 0xb6a0, 0x96d0, 0x95b0, //1980
|
|
|
|
0x49b0, 0xa4b8, 0xa4b0, 0xb258, 0x6a50, 0x6d40, 0xada0, 0xab60, 0x9370, 0x4978, //1990
|
|
|
|
0x4970, 0x64b0, 0x6a50, 0xea50, 0x6b28, 0x5ac0, 0xab60, 0x9368, 0x92e0, 0xc960, //2000
|
|
|
|
0xd4a8, 0xd4a0, 0xda50, 0x5aa8, 0x56a0, 0xaad8, 0x25d0, 0x92d0, 0xc958, 0xa950, //2010
|
|
|
|
0xb4a0, 0xb550, 0xb550, 0x55a8, 0x4ba0, 0xa5b0, 0x52b8, 0x52b0, 0xa930, 0x74a8, //2020
|
|
|
|
0x6aa0, 0xad50, 0x4da8, 0x4b60, 0x9570, 0xa4e0, 0xd260, 0xe930, 0xd530, 0x5aa0, //2030
|
|
|
|
0x6b50, 0x96d0, 0x4ae8, 0x4ad0, 0xa4d0, 0xd258, 0xd250, 0xd520, 0xdaa0, 0xb5a0, //2040
|
|
|
|
0x56d0, 0x4ad8, 0x49b0, 0xa4b8, 0xa4b0, 0xaa50, 0xb528, 0x6d20, 0xada0, 0x55b0 }; //2050
|
|
|
|
|
|
/// <summary>
|
|
/// 数组gLanarMonth存放阴历1901年到2050年闰月的月份,如没有则为0,每字节存两年
|
|
/// </summary>
|
|
private static byte[] gLunarMonth ={
|
|
0x00, 0x50, 0x04, 0x00, 0x20, //1910
|
|
|
|
0x60, 0x05, 0x00, 0x20, 0x70, //1920
|
|
|
|
0x05, 0x00, 0x40, 0x02, 0x06, //1930
|
|
|
|
0x00, 0x50, 0x03, 0x07, 0x00, //1940
|
|
|
|
0x60, 0x04, 0x00, 0x20, 0x70, //1950
|
|
|
|
0x05, 0x00, 0x30, 0x80, 0x06, //1960
|
|
|
|
0x00, 0x40, 0x03, 0x07, 0x00, //1970
|
|
|
|
0x50, 0x04, 0x08, 0x00, 0x60, //1980
|
|
|
|
0x04, 0x0a, 0x00, 0x60, 0x05, //1990
|
|
|
|
0x00, 0x30, 0x80, 0x05, 0x00, //2000
|
|
|
|
0x40, 0x02, 0x07, 0x00, 0x50, //2010
|
|
|
|
0x04, 0x09, 0x00, 0x60, 0x04, //2020
|
|
|
|
0x00, 0x20, 0x60, 0x05, 0x00, //2030
|
|
|
|
0x30, 0xb0, 0x06, 0x00, 0x50, //2040
|
|
|
|
0x02, 0x07, 0x00, 0x50, 0x03 }; //2050
|
|
|
|
/// <summary>
|
|
/// 数组gLanarHoliDay存放每年的二十四节气对应的阳历日期
|
|
/// 每年的二十四节气对应的阳历日期几乎固定,平均分布于十二个月中
|
|
/// 1月 2月 3月 4月 5月 6月
|
|
/// 小寒 大寒 立春 雨水 惊蛰 春分 清明 谷雨 立夏 小满 芒种 夏至
|
|
/// 7月 8月 9月 10月 11月 12月
|
|
/// 小暑 大暑 立秋 处暑 白露 秋分 寒露 霜降 立冬 小雪 大雪 冬至
|
|
/// 数据格式说明:
|
|
/// 如1901年的节气为
|
|
/// 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
|
|
/// 6, 21, 4, 19, 6, 21, 5, 21, 6,22, 6,22, 8, 23, 8, 24, 8, 24, 8, 24, 8, 23, 8, 22
|
|
/// 9, 6, 11,4, 9, 6, 10,6, 9,7, 9,7, 7, 8, 7, 9, 7, 9, 7, 9, 7, 8, 7, 15
|
|
/// 上面第一行数据为每月节气对应日期,15减去每月第一个节气,每月第二个节气减去15得第二行
|
|
/// 这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存放
|
|
/// 第二个节气的数据,可得下表
|
|
/// </summary>
|
|
private static byte[] gLunarHolDay ={
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1901
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1902
|
|
|
|
0x96, 0xA5, 0x87, 0x96, 0x87, 0x87, 0x79, 0x69, 0x69, 0x69, 0x78, 0x78, //1903
|
|
|
|
0x86, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x78, 0x87, //1904
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1905
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1906
|
|
|
|
0x96, 0xA5, 0x87, 0x96, 0x87, 0x87, 0x79, 0x69, 0x69, 0x69, 0x78, 0x78, //1907
|
|
|
|
0x86, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1908
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1909
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1910
|
|
|
|
0x96, 0xA5, 0x87, 0x96, 0x87, 0x87, 0x79, 0x69, 0x69, 0x69, 0x78, 0x78, //1911
|
|
|
|
0x86, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1912
|
|
|
|
0x95, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1913
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1914
|
|
|
|
0x96, 0xA5, 0x97, 0x96, 0x97, 0x87, 0x79, 0x79, 0x69, 0x69, 0x78, 0x78, //1915
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1916
|
|
|
|
0x95, 0xB4, 0x96, 0xA6, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x87, //1917
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x77, //1918
|
|
|
|
0x96, 0xA5, 0x97, 0x96, 0x97, 0x87, 0x79, 0x79, 0x69, 0x69, 0x78, 0x78, //1919
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1920
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x87, //1921
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x77, //1922
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x69, 0x69, 0x78, 0x78, //1923
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1924
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x87, //1925
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1926
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1927
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1928
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1929
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1930
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1931
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1932
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1933
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1934
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1935
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1936
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1937
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1938
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1939
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1940
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1941
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1942
|
|
|
|
0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1943
|
|
|
|
0x96, 0xA5, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1944
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1945
|
|
|
|
0x95, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1946
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1947
|
|
|
|
0x96, 0xA5, 0xA6, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1948
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x79, 0x78, 0x79, 0x77, 0x87, //1949
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1950
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1951
|
|
|
|
0x96, 0xA5, 0xA6, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1952
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1953
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x68, 0x78, 0x87, //1954
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1955
|
|
|
|
0x96, 0xA5, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1956
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1957
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1958
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1959
|
|
|
|
0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1960
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1961
|
|
|
|
0x96, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1962
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1963
|
|
|
|
0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1964
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1965
|
|
|
|
0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1966
|
|
|
|
0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1967
|
|
|
|
0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1968
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1969
|
|
|
|
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
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2039
|
|
|
|
0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x96, //2040
|
|
|
|
0xA5, 0xC3, 0xA5, 0xB5, 0xA5, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2041
|
|
|
|
0xA5, 0xB3, 0xA5, 0xB5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2042
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2043
|
|
|
|
0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x88, 0x87, 0x96, //2044
|
|
|
|
0xA5, 0xC3, 0xA5, 0xB4, 0xA5, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2045
|
|
|
|
0xA5, 0xB3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x87, //2046
|
|
|
|
0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2047
|
|
|
|
0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA5, 0x97, 0x87, 0x87, 0x88, 0x86, 0x96, //2048
|
|
|
|
0xA4, 0xC3, 0xA5, 0xA5, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x86, //2049
|
|
|
|
0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x78, 0x78, 0x87, 0x87 }; //2050
|
|
|
|
#endregion
|
|
|
|
#region 私有方法
|
|
/// <summary>
|
|
/// 判断当前日期所属的年份是否是闰年,私有函数
|
|
/// </summary>
|
|
/// <param name="pDate">
|
|
/// 日期
|
|
/// 格式:“2008-03-24”
|
|
/// </param>
|
|
/// <returns>是闰年:True ,不是闰年:False</returns>
|
|
private static bool IsRuYear(DateTime pDate)
|
|
{
|
|
int intYear;
|
|
intYear = pDate.Year;
|
|
|
|
if ((intYear % 400 == 0) || (intYear % 4 == 0 && intYear % 100 != 0))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 判断当前年份是否是闰年,私有函数
|
|
/// </summary>
|
|
/// <param name="pYear">
|
|
/// 年份
|
|
/// 格式:2008
|
|
/// </param>
|
|
/// <returns>是闰年:True ,不是闰年:False</returns>
|
|
private static bool IsRuYear(int pYear)
|
|
{
|
|
if ((pYear % 400 == 0) || (pYear % 4 == 0 && pYear % 100 != 0))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 日期处理方法
|
|
|
|
/// <summary>
|
|
/// 返回本年有多少天
|
|
/// </summary>
|
|
/// <param name="pYear">年份</param>
|
|
/// <returns>本年的天数</returns>
|
|
public static int GetDaysOfYear(int pYear)
|
|
{
|
|
|
|
#region
|
|
int intCnt = 0;
|
|
if (IsRuYear(pYear))
|
|
{
|
|
//闰年多 1 天 即:2 月为 29 天
|
|
intCnt = 366;
|
|
|
|
}
|
|
else
|
|
{
|
|
//--非闰年少1天 即:2 月为 28 天
|
|
intCnt = 365;
|
|
}
|
|
return intCnt;
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 本年有多少天
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns>本天在当年的天数</returns>
|
|
public static int GetDaysOfYear(DateTime pDate)
|
|
{
|
|
#region
|
|
int intYear;
|
|
|
|
//取得传入参数的年份部分,用来判断是否是闰年
|
|
|
|
intYear = pDate.Year;
|
|
|
|
if (IsRuYear(intYear))
|
|
{
|
|
//闰年多 1 天 即:2 月为 29 天
|
|
return 366;
|
|
}
|
|
else
|
|
{
|
|
//--非闰年少1天 即:2 月为 28 天
|
|
return 365;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 本月有多少天
|
|
/// </summary>
|
|
/// <param name="pYear">年</param>
|
|
/// <param name="pMonth">月</param>
|
|
/// <returns>天数</returns>
|
|
public static int GetDaysOfMonth(int pYear, int pMonth)
|
|
{
|
|
#region
|
|
int intDays = 0;
|
|
|
|
switch (pMonth)
|
|
{
|
|
case 1:
|
|
intDays = 31;
|
|
break;
|
|
case 2:
|
|
if (IsRuYear(pYear))
|
|
{
|
|
//闰年多 1 天 即:2 月为 29 天
|
|
intDays = 29;
|
|
}
|
|
else
|
|
{
|
|
//--非闰年少1天 即:2 月为 28 天
|
|
intDays = 28;
|
|
}
|
|
|
|
break;
|
|
case 3:
|
|
intDays = 31;
|
|
break;
|
|
case 4:
|
|
intDays = 30;
|
|
break;
|
|
case 5:
|
|
intDays = 31;
|
|
break;
|
|
case 6:
|
|
intDays = 30;
|
|
break;
|
|
case 7:
|
|
intDays = 31;
|
|
break;
|
|
case 8:
|
|
intDays = 31;
|
|
break;
|
|
case 9:
|
|
intDays = 30;
|
|
break;
|
|
case 10:
|
|
intDays = 31;
|
|
break;
|
|
case 11:
|
|
intDays = 30;
|
|
break;
|
|
case 12:
|
|
intDays = 31;
|
|
break;
|
|
}
|
|
|
|
return intDays;
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 本月有多少天
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns>天数</returns>
|
|
public static int GetDaysOfMonth(DateTime pDate)
|
|
{
|
|
|
|
#region
|
|
int intYear = pDate.Year;
|
|
int intMonth = pDate.Month;
|
|
int intDays = 0;
|
|
|
|
|
|
//--利用年月信息,得到当前月的天数信息。
|
|
switch (intMonth)
|
|
{
|
|
case 1:
|
|
intDays = 31;
|
|
break;
|
|
case 2:
|
|
if (IsRuYear(intYear))
|
|
{
|
|
//闰年多 1 天 即:2 月为 29 天
|
|
intDays = 29;
|
|
}
|
|
else
|
|
{
|
|
//--非闰年少1天 即:2 月为 28 天
|
|
intDays = 28;
|
|
}
|
|
|
|
break;
|
|
case 3:
|
|
intDays = 31;
|
|
break;
|
|
case 4:
|
|
intDays = 30;
|
|
break;
|
|
case 5:
|
|
intDays = 31;
|
|
break;
|
|
case 6:
|
|
intDays = 30;
|
|
break;
|
|
case 7:
|
|
intDays = 31;
|
|
break;
|
|
case 8:
|
|
intDays = 31;
|
|
break;
|
|
case 9:
|
|
intDays = 30;
|
|
break;
|
|
case 10:
|
|
intDays = 31;
|
|
break;
|
|
case 11:
|
|
intDays = 30;
|
|
break;
|
|
case 12:
|
|
intDays = 31;
|
|
break;
|
|
}
|
|
|
|
return intDays;
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 返回当前日期的星期名称
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns>星期名称</returns>
|
|
public static string GetWeekNameOfDay(DateTime pDate)
|
|
{
|
|
#region
|
|
string strDate;
|
|
string strWeek = "";
|
|
|
|
strDate = pDate.DayOfWeek.ToString();
|
|
|
|
switch (strDate)
|
|
{
|
|
case "Monday":
|
|
strWeek = "星期一";
|
|
break;
|
|
case "Tuesday":
|
|
strWeek = "星期二";
|
|
break;
|
|
case "Wednesday":
|
|
strWeek = "星期三";
|
|
break;
|
|
case "Thursday":
|
|
strWeek = "星期四";
|
|
break;
|
|
case "Friday":
|
|
strWeek = "星期五";
|
|
break;
|
|
case "Saturday":
|
|
strWeek = "星期六";
|
|
break;
|
|
case "Sunday":
|
|
strWeek = "星期日";
|
|
break;
|
|
|
|
}
|
|
return strWeek;
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 返回当前日期的星期编号
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns>星期数字编号</returns>
|
|
public static string GetWeekNumberOfDay(DateTime pDate)
|
|
{
|
|
#region
|
|
string strDate;
|
|
string strWeek = "";
|
|
|
|
strDate = pDate.DayOfWeek.ToString();
|
|
|
|
switch (strDate)
|
|
{
|
|
case "Monday":
|
|
strWeek = "1";
|
|
break;
|
|
case "Tuesday":
|
|
strWeek = "2";
|
|
break;
|
|
case "Wednesday":
|
|
strWeek = "3";
|
|
break;
|
|
case "Thursday":
|
|
strWeek = "4";
|
|
break;
|
|
case "Friday":
|
|
strWeek = "5";
|
|
break;
|
|
case "Saturday":
|
|
strWeek = "6";
|
|
break;
|
|
case "Sunday":
|
|
strWeek = "7";
|
|
break;
|
|
|
|
}
|
|
|
|
return strWeek;
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 返回两个日期之间相差的天数
|
|
/// </summary>
|
|
/// <param name="pFromDate">起始日期</param>
|
|
/// <param name="pToDate">结束日期</param>
|
|
/// <returns>天数</returns>
|
|
public static int DiffDays(DateTime pFromDate, DateTime pToDate)
|
|
{
|
|
#region
|
|
|
|
TimeSpan ts = pFromDate.Subtract(pToDate);
|
|
|
|
return ts.Days;
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回两个日期之间相差的天数
|
|
/// </summary>
|
|
/// <param name="pFromDate">起始日期</param>
|
|
/// <param name="pToDate">结束日期</param>
|
|
/// <returns>天数</returns>
|
|
public static int DiffDays(string pFromDate, string pToDate)
|
|
{
|
|
#region
|
|
DateTime datFromDate = Convert.ToDateTime(pFromDate);
|
|
DateTime datToDate = Convert.ToDateTime(pToDate);
|
|
|
|
TimeSpan ts = datFromDate.Subtract(datToDate);
|
|
|
|
return ts.Days;
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将输入的字符串转化为日期。如果字符串的格式非法,则返回当前日期。
|
|
/// </summary>
|
|
/// <param name="pDate">输入字符串</param>
|
|
/// <returns>日期对象</returns>
|
|
public static DateTime ConvertStringToDate(string pDate)
|
|
{
|
|
#region
|
|
DateTime datDateTime;
|
|
|
|
try
|
|
{
|
|
datDateTime = DateTime.Parse(pDate);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
datDateTime = DateTime.Today;
|
|
}
|
|
|
|
return datDateTime;
|
|
#endregion
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 将日期对象转化为格式字符串
|
|
/// </summary>
|
|
/// <param name="pDateTime">日期对象</param>
|
|
/// <param name="pFormat">
|
|
/// 格式:
|
|
/// "SHORTDATE"===短日期
|
|
/// "LONGDATE"==长日期
|
|
/// 其它====自定义格式
|
|
/// </param>
|
|
/// <returns>日期字符串</returns>
|
|
public static string ConvertDateToString(DateTime pDateTime, string pFormat)
|
|
{
|
|
#region
|
|
string strDate = "";
|
|
|
|
try
|
|
{
|
|
switch (pFormat.ToUpper())
|
|
{
|
|
case "SHORTDATE":
|
|
strDate = pDateTime.ToShortDateString();
|
|
break;
|
|
case "LONGDATE":
|
|
strDate = pDateTime.ToLongDateString();
|
|
break;
|
|
default:
|
|
strDate = pDateTime.ToString(pFormat);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
strDate = pDateTime.ToShortDateString();
|
|
}
|
|
|
|
return strDate;
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断是否为合法日期,必须大于1800年1月1日
|
|
/// </summary>
|
|
/// <param name="pDate">输入日期字符串</param>
|
|
/// <returns>True/False</returns>
|
|
public static bool IsDateTime(string pDate)
|
|
{
|
|
#region
|
|
try
|
|
{
|
|
DateTime datDate = DateTime.Parse(pDate);
|
|
if (datDate.CompareTo(DateTime.Parse("1800-1-1")) > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 农历日期处理方法
|
|
|
|
/// <summary>
|
|
/// 计算指定日期的星座序号
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns></returns>
|
|
public static int GetConstellation(DateTime pDate)
|
|
{
|
|
#region
|
|
int pYear, intMonth, intDay;
|
|
|
|
pYear = pDate.Year;
|
|
|
|
intMonth = pDate.Month;
|
|
|
|
intDay = pDate.Day;
|
|
|
|
pYear = intMonth * 100 + intDay;
|
|
|
|
if (((pYear >= 321) && (pYear <= 419))) { return 0;}
|
|
|
|
else if ((pYear >= 420) && (pYear <= 520)) { return 1;}
|
|
|
|
else if ((pYear >= 521) && (pYear <= 620)) { return 2;}
|
|
|
|
else if ((pYear >= 621) && (pYear <= 722)) { return 3;}
|
|
|
|
else if ((pYear >= 723) && (pYear <= 822)) { return 4;}
|
|
|
|
else if ((pYear >= 823) && (pYear <= 922)) { return 5;}
|
|
|
|
else if ((pYear >= 923) && (pYear <= 1022)) { return 6;}
|
|
|
|
else if ((pYear >= 1023) && (pYear <= 1121)) { return 7;}
|
|
|
|
else if ((pYear >= 1122) && (pYear <= 1221)) { return 8;}
|
|
|
|
else if ((pYear >= 1222) || (pYear <= 119)) { return 9;}
|
|
|
|
else if ((pYear >= 120) && (pYear <= 218)) { return 10;}
|
|
|
|
else if ((pYear >= 219) && (pYear <= 320)) { return 11;}
|
|
|
|
else { return -1;}
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算指定日期的星座名称
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns></returns>
|
|
public static string GetConstellationName(DateTime pDate)
|
|
{
|
|
#region
|
|
|
|
int intConstellation;
|
|
|
|
intConstellation = GetConstellation(pDate);
|
|
|
|
if ((intConstellation >= 0) && (intConstellation <= 11))
|
|
{
|
|
return ConstellationName[intConstellation];
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算公历当天对应的节气 0-23,-1表示不是节气
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns></returns>
|
|
public static int GetLunarHolDay(DateTime pDate)
|
|
{
|
|
#region
|
|
byte bytFlag;
|
|
|
|
int intHolDay, intYear, intMonth, intDay;
|
|
|
|
intYear = pDate.Year;
|
|
|
|
if ((intYear < START_YEAR) || (intYear > END_YEAR))
|
|
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
intMonth = pDate.Month;
|
|
|
|
intDay = pDate.Day;
|
|
|
|
bytFlag = gLunarHolDay[(intYear - START_YEAR) * 12 + intMonth - 1];
|
|
|
|
if (intDay < 15)
|
|
{
|
|
intHolDay = 15 - ((bytFlag >> 4) & 0x0f);
|
|
}
|
|
else
|
|
{
|
|
intHolDay = (bytFlag & 0x0f) + 15;
|
|
}
|
|
|
|
if (intDay == intHolDay)
|
|
{
|
|
|
|
if (intDay > 15)
|
|
{
|
|
return (intMonth - 1) * 2 + 1;
|
|
}
|
|
else
|
|
{
|
|
return (intMonth - 1) * 2;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 农历月显示
|
|
/// </summary>
|
|
/// <param name="pMonth">月</param>
|
|
/// <param name="pLunar"></param>
|
|
/// <returns></returns>
|
|
public static string FormatMonth(ushort pMonth, bool pLunar)
|
|
{
|
|
#region
|
|
string strText = "正二三四五六七八九十";
|
|
|
|
string strMonth = "";
|
|
|
|
if ((!pLunar) && (pMonth == 1))
|
|
{
|
|
return "一月";
|
|
}
|
|
|
|
if (pMonth <= 10)
|
|
|
|
{
|
|
strMonth = strMonth + strText.Substring(pMonth - 1, 1);
|
|
|
|
}
|
|
else if (pMonth == 11)
|
|
{
|
|
strMonth = "十一";
|
|
}
|
|
else
|
|
{
|
|
strMonth = "十二";
|
|
}
|
|
|
|
return strMonth + "月";
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 农历日显示
|
|
/// </summary>
|
|
/// <param name="pDay">日</param>
|
|
/// <returns></returns>
|
|
public static string FormatLunarDay(ushort pDay)
|
|
{
|
|
#region
|
|
string strText1 = "初十廿三";
|
|
string strText2 = "一二三四五六七八九十";
|
|
string strDay;
|
|
|
|
if ((pDay != 20) && (pDay != 30))
|
|
{
|
|
strDay = strText1.Substring((pDay - 1) / 10, 1);
|
|
strDay = strDay + strText2.Substring((pDay - 1) % 10, 1);
|
|
}
|
|
else
|
|
{
|
|
// strDay = szText1.Substring((pDay / 10) * 2 + 1, 2);
|
|
strDay = strText1.Substring((pDay / 10) , 1);
|
|
strDay = strDay + "十";
|
|
}
|
|
|
|
return strDay;
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 指定节气名称
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns></returns>
|
|
public static string GetLunarHolDayName(DateTime pDate)
|
|
{
|
|
#region
|
|
ushort intYear, intMonth, intDay;
|
|
|
|
int intHolDay;
|
|
|
|
TimeSpan ts;
|
|
|
|
intYear = (ushort)(pDate.Year);
|
|
|
|
if ((intYear < START_YEAR) || (intYear > END_YEAR))
|
|
{
|
|
return "";
|
|
}
|
|
|
|
intHolDay = GetLunarHolDay(pDate);
|
|
|
|
if ((intHolDay >= 0) && (intHolDay <= 23))
|
|
{
|
|
return LunarHolDayName[intHolDay];
|
|
}
|
|
else
|
|
{
|
|
ts = pDate - (new DateTime(START_YEAR, 1, 1));
|
|
CalcLunarDate(out intYear, out intMonth, out intDay, (uint)(ts.Days));
|
|
return FormatMonth(intMonth, true) + FormatLunarDay(intDay);
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回阴历pLunarYear年的闰月月份,如没有返回0 1901年1月---2050年12月
|
|
/// </summary>
|
|
/// <param name="pLunarYear">年</param>
|
|
/// <returns></returns>
|
|
public static int GetLeapMonth(ushort pLunarYear)
|
|
{
|
|
#region
|
|
|
|
byte bytFlag;
|
|
|
|
if ((pLunarYear < START_YEAR) || (pLunarYear > END_YEAR))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
bytFlag = gLunarMonth[(pLunarYear - START_YEAR) / 2];
|
|
|
|
if ((pLunarYear - START_YEAR) % 2 == 0)
|
|
{
|
|
return bytFlag >> 4;
|
|
}
|
|
else
|
|
{
|
|
return bytFlag & 0x0F;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回阴历iLunarYer年阴历pLunarMonth月的天数,如果pLunarMonth为闰月
|
|
/// 高字为第二个pLunarMonth月的天数,否则高字为0 1901年1月---2050年12月
|
|
/// </summary>
|
|
/// <param name="pLunarYear">年</param>
|
|
/// <param name="pLunarMonth">月</param>
|
|
/// <returns></returns>
|
|
public static uint LunarMonthDays(ushort pLunarYear, ushort pLunarMonth)
|
|
{
|
|
#region
|
|
|
|
int intHeight, intLow;
|
|
int intBit;
|
|
|
|
if ((pLunarYear < START_YEAR) || (pLunarYear > END_YEAR))
|
|
{
|
|
return 30;
|
|
}
|
|
|
|
intHeight = 0;
|
|
|
|
intLow = 29;
|
|
|
|
intBit = 16 - pLunarMonth;
|
|
|
|
if ((pLunarMonth > GetLeapMonth(pLunarYear)) && (GetLeapMonth(pLunarYear) > 0))
|
|
{
|
|
intBit--;
|
|
}
|
|
|
|
if ((gLunarMonthDay[pLunarYear - START_YEAR] & (1 << intBit)) > 0)
|
|
{
|
|
intLow++;
|
|
}
|
|
|
|
if (pLunarMonth == GetLeapMonth(pLunarYear))
|
|
{
|
|
|
|
if ((gLunarMonthDay[pLunarYear - START_YEAR] & (1 << (intBit-1)))>0)
|
|
{
|
|
intHeight = 30;
|
|
}
|
|
else
|
|
{
|
|
intHeight = 29;
|
|
}
|
|
|
|
}
|
|
|
|
return (uint)((uint)(intLow)|(uint)(intHeight)<<16); //合成为uint
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回阴历pLunarYear年的总天数 1901年1月---2050年12月
|
|
/// </summary>
|
|
/// <param name="pLunarYear">年</param>
|
|
/// <returns></returns>
|
|
public static int LunarYearDays(ushort pLunarYear)
|
|
{
|
|
#region
|
|
int intDays;
|
|
uint uintTmp;
|
|
|
|
if ((pLunarYear < START_YEAR) || (pLunarYear > END_YEAR))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
intDays = 0;
|
|
|
|
for (ushort intCnt=1; intCnt <= 12; intCnt++)
|
|
{
|
|
uintTmp = LunarMonthDays(pLunarYear, intCnt);
|
|
intDays = intDays + ((ushort)(uintTmp>>16) & 0xFFFF); //取高位
|
|
intDays = intDays + (ushort)(uintTmp); //取低位
|
|
}
|
|
|
|
return intDays;
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算从1901年1月1日过pSpanDays天后的阴历日期
|
|
/// </summary>
|
|
/// <param name="pYear">年</param>
|
|
/// <param name="pMonth">月</param>
|
|
/// <param name="pDay">日</param>
|
|
/// <param name="pSpanDays">间隔天数</param>
|
|
public static void CalcLunarDate(out ushort pYear, out ushort pMonth, out ushort pDay, uint pSpanDays)
|
|
{
|
|
#region
|
|
uint intTmp;
|
|
|
|
//阳历1901年2月19日为阴历1901年正月初一
|
|
//阳历1901年1月1日到2月19日共有49天
|
|
|
|
if (pSpanDays < 49)
|
|
|
|
{
|
|
|
|
pYear = START_YEAR - 1;
|
|
|
|
if (pSpanDays < 19)
|
|
{
|
|
pMonth = 11;
|
|
pDay = (ushort)(11 + pSpanDays);
|
|
}
|
|
else
|
|
{
|
|
pMonth = 12;
|
|
pDay = (ushort)(pSpanDays - 18);
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//下面从阴历1901年正月初一算起
|
|
|
|
pSpanDays = pSpanDays - 49;
|
|
|
|
pYear = START_YEAR;
|
|
|
|
pMonth = 1;
|
|
|
|
pDay = 1;
|
|
|
|
//计算年
|
|
|
|
intTmp = (uint)LunarYearDays(pYear);
|
|
|
|
while (pSpanDays >= intTmp)
|
|
{
|
|
pSpanDays = pSpanDays - intTmp;
|
|
pYear++;
|
|
intTmp = (uint)LunarYearDays(pYear);
|
|
}
|
|
|
|
//计算月
|
|
|
|
intTmp = LunarMonthDays(pYear, pMonth); //取低位
|
|
|
|
while (pSpanDays >= intTmp)
|
|
{
|
|
pSpanDays = pSpanDays - intTmp;
|
|
|
|
if (pMonth == GetLeapMonth(pYear))
|
|
{
|
|
intTmp = (LunarMonthDays(pYear, pMonth)>>16)&0xFFFF; //取高位
|
|
|
|
if (pSpanDays < intTmp)
|
|
{
|
|
break;
|
|
}
|
|
|
|
pSpanDays = pSpanDays - intTmp;
|
|
|
|
}
|
|
|
|
pMonth++;
|
|
|
|
intTmp = LunarMonthDays(pYear,pMonth); //取低位
|
|
|
|
}
|
|
|
|
//计算日
|
|
|
|
pDay = (ushort)(pDay + pSpanDays);
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 把pYear年格式化成天干记年法表示的字符串
|
|
/// </summary>
|
|
/// <param name="pDate">日期</param>
|
|
/// <returns></returns>
|
|
public string FormatLunarYear(DateTime pDate)
|
|
{
|
|
#region
|
|
string strYear;
|
|
|
|
string strTianGan = "甲乙丙丁戊己庚辛壬癸";
|
|
|
|
string strDiZhi = "子丑寅卯辰巳午未申酉戌亥";
|
|
|
|
string strShengXiao = "鼠牛虎免龙蛇马羊猴鸡狗猪";
|
|
|
|
ushort pYear;
|
|
|
|
pYear = (ushort)(pDate.Year);
|
|
|
|
strYear = strTianGan.Substring((pYear - 4) % 10, 1);
|
|
|
|
strYear = strYear + strDiZhi.Substring((pYear - 4) % 12, 1);
|
|
|
|
strYear = strYear + " ";
|
|
|
|
strYear = strYear + strShengXiao.Substring((pYear - 4) % 12, 1);
|
|
|
|
strYear = strYear + "年";
|
|
|
|
return strYear;
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|