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学习自修第六天【pycharm的使用】
1.在工程右键可选新建文件夹,包盒python文件 文件夹和包的区别在于,包包含一个空的__init__.py文件,而文件夹没有 2.pycharm的断点调试 点击Debug表示进入调试状态 点击Re ...
- Socket初见
前端代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <t ...
- hibernate一对多映射文件的配置
其中一个Customer对应多个LinkMan Customer的映射文件 Customer.hbm.xml-------------->一对多 <?xml version="1 ...
- http协议状态码大全
100 Continue:初始的请求已经接受,客户应当继续发送请求的其余部分. 101 Switching Protocols:服务器将遵从客户的请求转换到另外一种协议. 200 OK:一切正常, ...
- SpringBoot部署jar与war
jar部署与启动/关闭 1.打包 clean 清理已有target目录 package 重新打包 获取打包路径,通过 scp命令发送到服务器端,scp -P ${port} ${.jar} ${use ...
- BZOJ4317Atm的树&BZOJ2051A Problem For Fun&BZOJ2117[2010国家集训队]Crash的旅游计划——二分答案+动态点分治(点分树套线段树/点分树+vector)
题目描述 Atm有一段时间在虐qtree的题目,于是,他满脑子都是tree,tree,tree…… 于是,一天晚上他梦到自己被关在了一个有根树中,每条路径都有边权,一个神秘的声音告诉他,每个点到其他的 ...
- 欧拉筛法模板&&P3383 【模板】线性筛素数
我们先来看欧拉筛法 •为什么叫欧拉筛呢?这可能是跟欧拉有关 •但是为什么叫线性筛呢?因为它的复杂度是线性的,也就是O(n),我们直接来看代码 #include<cstdio> #inc ...
- 洛谷3704 [SDOI2017] 数字表格 【莫比乌斯反演】
题目分析: 比较有意思,但是套路的数学题. 题目要求$ \prod_{i=1}^{n} \prod_{j=1}^{m}Fib(gcd(i,j)) $. 注意到$ gcd(i,j) $有大量重复,采用莫 ...
- Linux qemu-nbd mount qemu disk image
Linux qemu-nbd mount qemu disk image deepin@deepin:~$ deepin@deepin:~$ qemu-nbd --help Usage: qemu-n ...
- BSGS及扩展BSGS总结(BSGS,map)
蒟蒻哪里有什么总结,只能点击%YL% 还有这位ZigZagK大佬的blog \(\mbox{BSGS}\) 模板题:洛谷P3846 [TJOI2007]可爱的质数 给定\(a,b\)和模数\(\mbo ...