代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
ASP.NET显示农历时间
作者:
Dezai.CN
/ 发布于
2012/10/25
/
616
ASP.NET显示农历时间
<div>public string ChineseTimeNow = "";</div> <div> public string ForignTimeNow = "";</div> <div> private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();</div> <div> private static string ChineseNumber = "〇一二三四五六七八九";</div> <div> public const string CelestialStem = "甲乙丙丁戊己庚辛壬癸";</div> <div> public const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥";</div> <div> public static readonly string[] ChineseDayName = new string[] {</div> <div> "初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",</div> <div> "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",</div> <div> "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};</div> <div> public static readonly string[] ChineseMonthName = new string[] { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };</div> <div></div> <div> override protected void Page_Load(object sender, EventArgs e)</div> <div> {</div> <div> base.Page_Load(sender, e);</div> <div> userName = Session["Admin"].ToString();</div> <div> ChineseTimeNow=GetChineseDate(DateTime.Now);</div> <div> ForignTimeNow = DateTime.Now.GetDateTimeFormats('D')[0].ToString();</div> <div> } <div></div> <div> /// <summary></div> <div> /// 获取一个公历日期对应的完整的农历日期</div> <div> /// </summary></div> <div> /// <param name="time">一个公历日期</param></div> <div> /// <returns>农历日期</returns></div> <div> public string GetChineseDate(DateTime time)</div> <div> {</div> <div> string strY = GetYear(time);</div> <div> string strM = GetMonth(time);</div> <div> string strD = GetDay(time);</div> <div> string strSB = GetStemBranch(time);</div> <div> string strDate = strY + "(" + strSB + ")年 " + strM + "月 " + strD;</div> <div> return strDate;</div> <div> } <div> /// <summary></div> <div> /// 获取一个公历日期的农历干支纪年</div> <div> /// </summary></div> <div> /// <param name="time">一个公历日期</param></div> <div> /// <returns>农历干支纪年</returns></div> <div> public string GetStemBranch(DateTime time)</div> <div> {</div> <div> int sexagenaryYear = calendar.GetSexagenaryYear(time);</div> <div> string stemBranch = CelestialStem.Substring(sexagenaryYear % 10 - 1, 1) + TerrestrialBranch.Substring(sexagenaryYear % 12 - 1, 1);</div> <div> return stemBranch;</div> <div> } <div></div> <div> /// <summary></div> <div> /// 获取一个公历日期的农历年份</div> <div> /// </summary></div> <div> /// <param name="time">一个公历日期</param></div> <div> /// <returns>农历年份</returns></div> <div> public string GetYear(DateTime time)</div> <div> {</div> <div> StringBuilder sb = new StringBuilder();</div> <div> int year = calendar.GetYear(time);</div> <div> int d;</div> <div> do</div> <div> {</div> <div> d = year % 10;</div> <div> sb.Insert(0, ChineseNumber[d]);</div> <div> year = year / 10;</div> <div> } while (year > 0);</div> <div> return sb.ToString();</div> <div> } <div></div> <div> /// <summary></div> <div> /// 获取一个公历日期的农历月份</div> <div> /// </summary></div> <div> /// <param name="time">一个公历日期</param></div> <div> /// <returns>农历月份</returns></div> <div> public string GetMonth(DateTime time)</div> <div> {</div> <div> int month = calendar.GetMonth(time);</div> <div> int year = calendar.GetYear(time);</div> <div> int leap = 0;</div> <div></div> <div> //正月不可能闰月</div> <div> for (int i = 3; i <= month; i++)</div> <div> {</div> <div> if (calendar.IsLeapMonth(year, i))</div> <div> {</div> <div> leap = i;</div> <div> break; //一年中最多有一个闰月</div> <div> } <div></div> <div> } <div> if (leap > 0) month--;</div> <div> return (leap == month + 1 ? "闰" : "") + ChineseMonthName[month - 1];</div> <div> } <div></div> <div></div> <div> /// <summary></div> <div> /// 获取一个公历日期的农历日</div> <div> /// </summary></div> <div> /// <param name="time">一个公历日期</param></div> <div> /// <returns>农历日</returns></div> <div> public string GetDay(DateTime time)</div> <div> {</div> <div> return ChineseDayName[calendar.GetDayOfMonth(time) - 1];</div> <div> }
试试其它关键字
显示农历时间
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3