usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceAlgorithmPractice

{public partial class公历转农历 : Form

{public公历转农历()

{

InitializeComponent();

}private void 公历转农历_Load(objectsender, EventArgs e)

{

BindYear();this.cbYear.SelectedItem =DateTime.Now.Year;this.cbMonth.SelectedItem =DateTime.Now.Month;this.cbDay.SelectedItem =DateTime.Now.Day;

btnChange_Click(sender,e);

}//绑定年份

public voidBindYear()

{

List arrYear = new List();for (int i = 0; i <= 2101 - 1901; i++)

{

arrYear.Insert(i,1901 +i);

}this.cbYear.DataSource =arrYear;

}//月份随年份而变

private void cbYear_SelectedIndexChanged(objectsender, EventArgs e)

{int[] year1901 = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};int[] year2101 = { 1};int[] yearOther = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};if (this.cbYear.Text == "1901")

{this.cbMonth.DataSource =year1901;

}else if (this.cbYear.Text == "2101")

{this.cbMonth.DataSource =year2101;

}else{this.cbMonth.DataSource =yearOther;

}

}//开始转换

private void btnChange_Click(objectsender, EventArgs e)

{try{string date = this.cbYear.Text + "-" + cbMonth.Text + "-" +cbDay.Text;

DateTime dt=Convert.ToDateTime(date);this.lblNongLi.Text =SolarToChineseLunisolarDate(dt);

}catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}///

///公历转为农历的函数///

/// 公历日期

/// 农历的日期

public static stringSolarToChineseLunisolarDate(DateTime solarDateTime)

{//微软的ChineseLunisolarCalendar 方法支持时间范围是[1901-2-19,2101-1-28]

System.Globalization.ChineseLunisolarCalendar cal = newSystem.Globalization.ChineseLunisolarCalendar();int year = cal.GetYear(solarDateTime);//农历年份

int month = cal.GetMonth(solarDateTime);//有闰月时该值可能为13,即leapMonth <= month ? month - 1 : month表示实际农历月份

int day = cal.GetDayOfMonth(solarDateTime);//农历天数

int leapMonth = cal.GetLeapMonth(year);//此年份闰几月,闰n月则返回n+1,如闰4月返回值为5;没有闰月返回0

String impday = "";//一年中的农历节日

String leapMonthStr = leapMonth > 0 ? "(闰" + (leapMonth - 1).ToString() + "月)" : "";//闰月份

int monthtrue = leapMonth > 0 && leapMonth <= month ? month - 1 : month;//把闰月计算进去之后真正的农历月份

if (monthtrue == 1 && day == 1)

{

impday= "春节";

}else if (monthtrue == 5 && day == 5)

{

impday= "端午";

}else if (monthtrue == 8 && day == 15)

{

impday= "中秋";

}

String month2= String.Format("{0}{1}月", month == leapMonth ? "闰" : "","无正二三四五六七八九十冬腊"[monthtrue]

);

String day2= string.Format("{0}{1}","初十廿三"[day == 10 ? 0 : day / 10]

,"十一二三四五六七八九"[day % 10]

);

String date= year + "年" + month2 +day2;if (impday != "")

{return date + leapMonthStr + " " + "祝您" + impday + "节快乐 ^-^";

}else

return date +leapMonthStr;

}//日子随月份改变

private void comboBox1_SelectedIndexChanged(objectsender, EventArgs e)

{if (String.IsNullOrEmpty(this.cbYear.Text.Trim()))

{

MessageBox.Show("年份不能为空!");return;

}try{int[] month31 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};int[] month30 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};int[] month29 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29};int[] month28 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28};int[] month190102 = { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29};int[] month210101 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28};

String strmonth= this.cbMonth.Text.Trim();

String stryear= this.cbYear.Text.Trim();if (stryear == "1901" && strmonth == "2")

{this.cbDay.DataSource =month190102;

}else if (stryear == "2101" && strmonth == "1")

{this.cbDay.DataSource =month210101;

}else{if (strmonth == "1" || strmonth == "3" || strmonth == "5" || strmonth == "7" || strmonth == "8" || strmonth == "10" || strmonth == "12")

{this.cbDay.DataSource =month31;

}else if (strmonth == "4" || strmonth == "9" || strmonth == "6" || strmonth == "11")

{this.cbDay.DataSource =month30;

}else if (strmonth == "2")

{if (System.DateTime.IsLeapYear(Convert.ToInt32(this.cbYear.Text.Trim())) == true)

{this.cbDay.DataSource = month29;//闰年

}else{this.cbDay.DataSource =month28;

}

}

}

}catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

}

}

mysql 计算农历_公历转换农历算法相关推荐

  1. JavaScript实现公历转换农历

    相信有人会在页面中中选择日期时,需要知道选择日期的农历!如果是Java的话,在后台一下子就可以给转换掉,但是页面上,通过JavaScript来转换的话,不知道大伙儿有没有好的想法呢?刚好,前一段时间来 ...

  2. js 根据公历日期 算出农历_根据公历日期计算农历年生肖及公历转换农历的方法...

    本帖最后由 wshcw 于 2011-12-6 23:23 编辑 有部分E友都知道,农历格式"[$-130000]e-m-d"转换出来的结果有好大一部分有误,那有没有其它转换办法呢 ...

  3. Python公历转换农历及简易万年历

    一般使用的万年历,只提供距今前后百年的日历.这是因为其所用的计算方法是一种简便的近似计算,适用范围较小.其次,天文学方法计算量大,不适合日常软件使用.但如果要进行历史研究,范围就超出常用日历,本文即实 ...

  4. 公历转农历matlab,公历转农历

    从网上找到一个公历转农历的程序.用途可能不是太广泛,但: A需要的时候去编写,还是蛮难的,B:编程方法可供参考. 从这个网址拷贝过来的http://top99.blog.hexun.com/45657 ...

  5. mysql最大公约数_最大公约数用算法

    世界上最早的算法:辗转相除法(求两个自然数最大公约数) 在数学界,辗转相除法,又称欧几里得算法,被认为是世界上最早的算法(公元前300年),该算法用于求两个最大公约数的算法.辗转相除法首次出现于欧几里 ...

  6. python牛顿法计算平方根_常用的平方根算法详解与实现

    本文从属于笔者的数据结构与算法系列文章. SquareRoot 平方根计算一直是计算系统的常用算法,本文列举出几张简单易懂的平方根算法讲解与实现.其中Java版本的代码参考这里 Reference B ...

  7. mysql数据转换英文_数据库转换工具下载_SqliteToMysql英文版2.5 - 系统城

    SqliteToMysql是一款专门用来完成数据库数据转换的软件,通过该软件,我们可以将Sqlite数据库和Mysql数据库数据的互相转换,这样你就可以将一些重要的数据快速完成转换和备份,有需要的小伙 ...

  8. 公历转换农历的算法(JavaScript)

    <!--   中国农历开始   --> <SCRIPT language=JavaScript> <!-- var lunarInfo=new Array( 0x04bd ...

  9. java 公历 农历_求JAVA农历转公历,公历转农历算法

    public class Lunar { private int year; private int month; private int day; private boolean leap; fin ...

  10. python万年历差农历程序_公历转农历的python实现

    1 #lunar.py 2 # 2015/02/27 罗兵 3 importdatetime4 5 classLunar(object):6 #**************************** ...

最新文章

  1. c3074 无法使用带圆括号的_小学生常见易考标点符号使用方法及练习(含答案)...
  2. linux svn 命令
  3. jQuery课程介绍、Query的介绍、Query初次体验、jQuery再次体验、jQuery中的顶级对象
  4. js 闭包函数 构造函数_JavaScript中的闭包,库里函数和酷抽象
  5. Sql Server之数据类型详解
  6. 京东怎么在线联系客服
  7. log4j:warn找不到_修复log4j WARN找不到记录器的附加程序,请正确初始化log4j系统
  8. LeetCode动态规划系列教程(下)
  9. 天天都在用的 Nginx,可你知道如何用一个反向代理实现多个不同类型的后端网站访问吗?...
  10. dubbo k8s 服务发现_Dubbo-go 发布 1.5 版,朝云原生迈出关键一步
  11. SG2525_电压模式PWM——科时进商城
  12. Linux 用户必须知道的 14 个常用 Linux 终端快捷键
  13. PMP工具与技术总结
  14. 最完美开启三星note9USB调试模式的方法
  15. 硬件设计基础----MOS管
  16. find:paths must precede expression问题及解决
  17. oracle如何写不等于号,Oracle中不等于号问题-Oracle
  18. RxJava 过滤操作符 ofType
  19. Hadoop Streaming 实战: 多路输出
  20. 第三方二维码收款平台 哪家好

热门文章

  1. 神威太湖之光入门指南
  2. 解决W5500,DHCP获取IP地址失败的问题,移植官方例程需要特别注意!!!
  3. 如何创建一个原始Mac OS镜像
  4. iOS包体积优化实践
  5. 硬件设计-DIY功放
  6. CocosCreator学习示例合集v3.4.2
  7. 简单典型二阶系统_【文献选译】二阶弹性波动方程PML的简单实现
  8. 卡尔曼滤波原在温度测量中的应用
  9. 129页4万字某智慧能源集团数字化管控平台项目 建设方案
  10. 获取百度地图开发平台的key