首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#NET将输入日期与农历日期对应有关问题,求解

2012-10-17 
C#.NET将输入日期与农历日期对应问题,求解using Systemusing System.Collections.Genericusing System.W

C#.NET将输入日期与农历日期对应问题,求解
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Globalization;

public partial class _Default : System.Web.UI.Page 
{
  private static ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar();
  protected void Page_Load(object sender, EventArgs e)
  {
  ShowCurrentYearInfo();
  }
  protected void btnok_Click(object sender, EventArgs e)
  {
  Session["year"] = year.Text;
  int y = Convert.ToInt32(Session["year"]);
  if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
  {
  Response.Write(Session["year"] + "是闰年");
  }
  else
  {
  Response.Write(Session["year"] + "不是闰年");
  }

  }
  private void ShowCurrentYearInfo()
  {
   
  int inYear = Convert.ToInt32(year.Text);
  int inMonth = Convert.ToInt32(month.Text);
  int inDate = Convert.ToInt32(date.Text);

  int lYear = chineseDate.GetYear(DateTime.Now);
  int lMonth = chineseDate.GetMonth(DateTime.Now);
  int lDate = chineseDate.GetDayOfMonth(DateTime.Now);

  /** GetLeapMonth(int year)方法返回一个1到13之间的数字,  
  * 比如:1、该年阴历2月有闰月,则返回3  
  * 如果:2、该年阴历8月有闰月,则返回9  
  * GetMonth(DateTime dateTime)返回是当前月份,忽略是否闰月  
  * 比如:1、该年阴历2月有闰月,2月返回2,闰2月返回3  
  * 如果:2、该年阴历8月有闰月,8月返回8,闰8月返回9  
  */
  int leapMonth = chineseDate.GetLeapMonth(lYear);//获取第几个月是闰月,等于0表示本年无闰月
  //如果今年有闰月  
  if (leapMonth > 0)
  {
  //闰月数等于当前月份  
  if (lMonth == leapMonth)
  {
  Response.Write("当前输入日期的农历日期:" + lYear + "年" + (lMonth - 1) + "月" + lDate + "日" );
  //Console.WriteLine("今年的阴历日期:{0}年闰{1}月{2}日。", lYear, lMonth - 1, lDay);
  }
  else if (lMonth > leapMonth) 
  {
  Response.Write("当前输入日期的农历日期:" + lYear + "年" + (lMonth - 1) + "月" + lDate + "日");
  //Console.WriteLine("今年的阴历日期:{0}年{1}月{2}日。", lYear, lMonth - 1, lDay);
  }
  else
  {
  Response.Write("当前输入日期的农历日期:" + lYear + "年" + lMonth + "月" + lDate + "日");
  //Console.WriteLine("今年的阴历日期:{0}年{1}月{2}日。", lYear, lMonth, lDay);
  }

  }
  else
  {
  Response.Write("当前输入日期的农历日期:" + lYear + "年" + lMonth + "月" + lDate + "日");
  //Console.WriteLine("今年的阴历日期:{0}年{1}月{2}日。", lYear, lMonth, lDay);
  }

  //throw new NotImplementedException();
  }
}

怎么使lYear输出的农历日期是inYear所对应的啊?

[解决办法]
给你贴个链接
http://hi.baidu.com/liyukun8203/item/3e8193bc4551cf41bb0e12a5
[解决办法]

探讨

int inYear = Convert.ToInt32(year.Text);


int inMonth = Convert.ToInt32(month.Text);
int inDate = Convert.ToInt32(date.Text);
NongLi bllNL = new NongLi();
int str =……

热点排行