C#项目获取当前时间的农历时间
https://blog.csdn.net/cstester/article/details/7407044
- using System.Globalization;
- class CnCanlendar_nongli
- {
- /// <summary>
- /// 实例化一个 ChineseLunisolarCalendar
- /// </summary>
- private static ChineseLunisolarCalendar ChineseCalendar = new ChineseLunisolarCalendar();
- /// <summary>
- /// 十天干
- /// </summary>
- private static string[] tg = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
- /// <summary>
- /// 十二地支
- /// </summary>
- private static string[] dz = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
- /// <summary>
- /// 十二生肖
- /// </summary>
- private static string[] sx = { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
- /// <summary>
- /// 返回农历天干地支年
- /// </summary>
- /// <param name="year">农历年</param>
- /// <returns></returns>
- public static string GetLunisolarYear(int year)
- {
- if (year > 3)
- {
- int tgIndex = (year - 4) % 10;
- int dzIndex = (year - 4) % 12;
- return string.Concat(tg[tgIndex], dz[dzIndex], "[", sx[dzIndex], "]");
- }
- throw new ArgumentOutOfRangeException("无效的年份!");
- }
- /// <summary>
- /// 农历月
- /// </summary>
- /// <returns></returns>
- private static string[] months = { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)" };
- /// <summary>
- /// 农历日
- /// </summary>
- private static string[] days1 = { "初", "十", "廿", "三" };
- /// <summary>
- /// 农历日
- /// </summary>
- private static string[] days = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
- /// <summary>
- /// 返回农历月
- /// </summary>
- /// <param name="month">月份</param>
- /// <returns></returns>
- public static string GetLunisolarMonth(int month)
- {
- if (month < 13 && month > 0)
- {
- return months[month - 1];
- }
- throw new ArgumentOutOfRangeException("无效的月份!");
- }
- /// <summary>
- /// 返回农历日
- /// </summary>
- /// <param name="day">天</param>
- /// <returns></returns>
- public static string GetLunisolarDay(int day)
- {
- if (day > 0 && day < 32)
- {
- if (day != 20 && day != 30)
- {
- return string.Concat(days1[(day - 1) / 10], days[(day - 1) % 10]);
- }
- else
- {
- return string.Concat(days[(day - 1) / 10], days1[1]);
- }
- }
- throw new ArgumentOutOfRangeException("无效的日!");
- }
- /// <summary>
- /// 根据公历获取农历日期
- /// </summary>
- /// <param name="datetime">公历日期</param>
- /// <returns></returns>
- public static string GetChineseDateTime(DateTime datetime)
- {
- //农历的年月日
- int year = ChineseCalendar.GetYear(datetime);
- int month = ChineseCalendar.GetMonth(datetime);
- int day = ChineseCalendar.GetDayOfMonth(datetime);
- //获取闰月, 0 则表示没有闰月
- int leapMonth = ChineseCalendar.GetLeapMonth(year);
- bool isleap = false;
- if (leapMonth > 0)
- {
- if (leapMonth == month)
- {
- //闰月
- isleap = true;
- month--;
- }
- else if (month > leapMonth)
- {
- month--;
- }
- }
- return string.Concat(GetLunisolarYear(year), "年", isleap ? "闰" : string.Empty, GetLunisolarMonth(month), "月", GetLunisolarDay(day));
- }
- }
C#项目获取当前时间的农历时间的更多相关文章
- 代码空间项目 -- 获取当前时间之前的某一天-Calender类的使用
Calendar类的静态方法getInstance()可以初始化一个日历对象:Calendar now = Calendar.getInstance(); 1.Calendar的基本用法calenda ...
- js获取当前农历时间
<template> <div class="gaia-header"> <img alt="gaia_logo" src=&qu ...
- ASP.NET农历时间显示(两)
在拍摄的月球时前(http://blog.csdn.net/yysyangyangyangshan/article/details/6802950),只是没有进行封装使用起来须要手动改动. 本次进行简 ...
- ASP.NET如何显示农历时间
ASP.NET如何显示农历时间 CS部分代码如下: 代码如下: public string ChineseTimeNow = ""; public string ForignTi ...
- 项目心得——按照指定的日期/时间创建Date对象
项目心得——按照指定的日期/时间创建Date对象 有时,在做项目中,需要获得指定日期的Date对象,这个指定的日期或者时间可能不是当前的时间.下面讲解两种获取指定日期/时间的Date对象的方法: pa ...
- Java 获取当前时间及实现时间倒计时功能
引言 在一些项目中或是一些特殊的业务场景中,需要用到显示系统的当前时间,以及一些固定的时间倒计时,时间到后做一些什么事情的业务 .接下来咱们就具体看看代码是怎么实现的: <%@ page lan ...
- 用PHP获取系统时间时,时间比当前时间少8个小时
自PHP5.0开始,用PHP获取系统时间时,时间比当前时间少8个小时.原因是PHP.ini中没有设置timezone时,PHP是使用的UTC时间,所以在中国时间要少8小时. 解决办法: 1.在PHP. ...
- [WinAPI] API 14 [获取、设置文件属性和时间]
>_< 为了获取文件属性,用户可以使用GetFileAttributes与GetFileAttributesEx函数. GetFileAttributesEx函数除了返回文件属性外,还返回 ...
- Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数
格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...
随机推荐
- python(Django之Logging、API认证)
一.Loging模块 用于方便的记录日志的模块 import logging logging.basicConfig(filename='log.log', format='%(asctime)s - ...
- CSS自定义属性expression_r
CSS的出现使网页制作者在对网页元素的控制方便许多,当然,有利必有弊,CSS只能对颜色.大小.距离等静态样式有效,对于要实现某些html元素的动态样式就显得有些力不从心.有了CSS的自定义属性expr ...
- win10远程桌面连接提示身份验证错误,要求的函数不受支持的解决方案
转自https://www.baidu.com/link?url=67JXh4h79mN47mEenuH_ElGkSh9_GdOiY-Xp9Ihw0_mQIZHrPx-HxY3EIm_nTZKPoRZ ...
- LODOP循环多任务 同模版只设置不同队列任务名
LODOP中从PRINT_INIT(或PRINT_INITA)到最后PRINT(或PREVIEW等),是一个任务,关于Lodop中一个任务,以及一个任务中可以包含哪些语句,详细可查看本博客另一篇博文: ...
- 利用H5 FormData 实现表单中多图上传(可带其他如String类型数据)
本篇的具体思路来源于右侧网址:http://blog.csdn.net/qq_19551571/article/details/49977983 本篇代码有所修改,请具体区分. 本篇使用的是 form ...
- Opencv画图操作
1. 画矩形 MyRect rect;rect.left = 5;rect.top = 5;rect.right = 100;rect.bottom = 100;IplImage * pColorIm ...
- faster rcnn训练自己的数据集
采用Pascal VOC数据集的组织结构,来构建自己的数据集,这种方法是faster rcnn最便捷的训练方式
- 使用cmd命令行窗口操作SqlServer
本文主要介绍使用windows下的使用cmd命令行窗口操作Sqlserver, 首先我们可以运行 osql ?/ ,这样就把所有可以通过CMD命令行操作sqlserver的命令显示出来 (有图有 ...
- Nginx 反向代理如何连接上游服务器
L:92 想上游服务器先建立TCP连接 如三次握手 下面指令可以控制握手时间 proxy_next_upstream 指令当出现502可以换个上游服务器 Tcp keepalive 一般都是由进程在 ...
- Qt 获取屏幕信息
void GetScreenInfo() { QDesktopWidget* desktopWidget = QApplication::desktop(); //获取可用桌面大小 QRect des ...