无为清净楼资源网 Design By www.qnjia.com

本文实例讲述了ASP.NET显示农历时间的方法。分享给大家供大家参考。具体实现方法如下:

CS部分代码如下:
复制代码 代码如下:public string ChineseTimeNow = ""; 
public string ForignTimeNow = ""; 
private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar(); 
private static string ChineseNumber = "〇一二三四五六七八九"; 
public const string CelestialStem = "甲乙丙丁戊己庚辛壬癸"; 
public const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥"; 
public static readonly string[] ChineseDayName = new string[] { 
        "初一","初二","初三","初四","初五","初六","初七","初八","初九","初十", 
        "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十", 
        "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"}; 
public static readonly string[] ChineseMonthName = new string[] { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" }; 

override protected void Page_Load(object sender, EventArgs e) 

        base.Page_Load(sender, e); 
        userName = Session["Admin"].ToString(); 
        ChineseTimeNow=GetChineseDate(DateTime.Now); 
        ForignTimeNow = DateTime.Now.GetDateTimeFormats('D')[0].ToString(); 

/// <summary> 
/// 获取一个公历日期对应的完整的农历日期 
/// </summary> 
/// <param name="time">一个公历日期</param> 
/// <returns>农历日期</returns> 
public string GetChineseDate(DateTime time) 

        string strY = GetYear(time); 
        string strM = GetMonth(time); 
        string strD = GetDay(time); 
        string strSB = GetStemBranch(time); 
        string strDate = strY + "(" + strSB + ")年 " + strM + "月 " + strD; 
        return strDate; 

/// <summary> 
/// 获取一个公历日期的农历干支纪年 
/// </summary> 
/// <param name="time">一个公历日期</param> 
/// <returns>农历干支纪年</returns> 
public string GetStemBranch(DateTime time) 

        int sexagenaryYear = calendar.GetSexagenaryYear(time); 
        string stemBranch = CelestialStem.Substring(sexagenaryYear % 10 - 1, 1) + TerrestrialBranch.Substring(sexagenaryYear % 12 - 1, 1); 
        return stemBranch; 

/// <summary> 
/// 获取一个公历日期的农历年份 
/// </summary> 
/// <param name="time">一个公历日期</param> 
/// <returns>农历年份</returns> 
public string GetYear(DateTime time) 

        StringBuilder sb = new StringBuilder(); 
        int year = calendar.GetYear(time); 
        int d; 
        do 
        { 
            d = year % 10; 
            sb.Insert(0, ChineseNumber[d]); 
            year = year / 10; 
        } while (year > 0); 
        return sb.ToString(); 

/// <summary> 
/// 获取一个公历日期的农历月份 
/// </summary> 
/// <param name="time">一个公历日期</param> 
/// <returns>农历月份</returns> 
public string GetMonth(DateTime time) 

        int month = calendar.GetMonth(time); 
        int year = calendar.GetYear(time); 
        int leap = 0; 
 
        //正月不可能闰月 
        for (int i = 3; i <= month; i++) 
        { 
            if (calendar.IsLeapMonth(year, i)) 
            { 
                leap = i; 
                break; //一年中最多有一个闰月 
            } 
 
        } 
        if (leap > 0) month--; 
        return (leap == month + 1 "闰" : "") + ChineseMonthName[month - 1]; 

/// <summary> 
/// 获取一个公历日期的农历日 
/// </summary> 
/// <param name="time">一个公历日期</param> 
/// <returns>农历日</returns> 
public string GetDay(DateTime time) 

        return ChineseDayName[calendar.GetDayOfMonth(time) - 1]; 
}

前台部分代码如下:
复制代码 代码如下:<table style=""> 
 <tr valign="bottom"> 
<td valign="bottom"> <%=ForignTimeNow%><br /></td 
   </tr> 
   <tr valign="bottom"> 
  <td valign="bottom"> <%=ChineseTimeNow %></td> 
 </tr> 
 </table>

 希望本文所述对大家的ASP.NET程序设计有所帮助。

标签:
ASP.NET,显示,农历,时间

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。