您的位置:首页 > 编程语言 > ASP

asp.net中如何将阳历转化为阴历(C#)

2008-12-05 16:28 344 查看
我们有的时候会用到阴历来做一些事情,在1.1的时候,只能用第三方的方法。现在2.0中给了自己的方法,不多说了,放一个例子。
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

请输入阳历日期:<asp:TextBox ID="txtSun" runat="server"></asp:TextBox>
<br />
<br />
阳历日期:<asp:TextBox ID="txtMoon" runat="server" ></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="转换" onclick="Button1_Click" />

</div>
</form>
</body>
</html>

后台“

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
private ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar();

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
string Moon = chineseDate.GetYear(Convert.ToDateTime(this.txtSun.Text.Trim())).ToString() + "-" + chineseDate.GetMonth(Convert.ToDateTime(this.txtSun.Text.Trim())).ToString() + "-" + chineseDate.GetDayOfMonth(Convert.ToDateTime(this.txtSun.Text.Trim()));
this.txtMoon.Text = Moon;
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: