这是网上的例子,你仔细看看
using System;
using SystemData;
using SystemConfiguration;
using SystemWeb;
using SystemWebSecurity;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIWebControlsWebParts;
using SystemWebUIHtmlControls;
using System;
using SystemCollectionsGeneric;
using SystemText;
using SystemGlobalization;
/// <summary>
/// chinaDate 的摘要说明
/// </summary>
public class chinaDate
{
public string cDate()
{
ChineseLunisolarCalendar l = new ChineseLunisolarCalendar();
DateTime dt = DateTimeToday; //转换当日的日期
//dt = new DateTime(2006, 1,29);//农历2006年大年初一(测试用),也可指定日期转换
string[] aMonth ={"","正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月", "腊月" };
//a10表示日期的十位!
string[] a10 ={ "初", "十", "廿", "卅" };
string[] aDigi ={ "O", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string sYear = "", sYearArab = "", sMonth = "", sDay = "", sDay10 = "", sDay1 = "", sLuniSolarDate = "";
int iYear, iMonth, iDay;
iYear = lGetYear(dt);
iMonth = lGetMonth(dt);
iDay = lGetDayOfMonth(dt);
//Format Year
sYearArab = iYearToString();
for (int i = 0; i < sYearArabLength; i++)
{
sYear += aDigi[ConvertToInt16(sYearArabSubstring(i, 1))];
}
//Format Month
int iLeapMonth = lGetLeapMonth(iYear); //获取闰月
if (iLeapMonth > 0 && iMonth<=iLeapMonth)
{
//for (int i = iLeapMonth + 1; i < 13; i++) aMonth[i] = aMonth[i - 1];
aMonth[iLeapMonth] = "闰" + aMonth[iLeapMonth-1];
sMonth = aMonth[lGetMonth(dt)];
}
else if (iLeapMonth > 0 && iMonth > iLeapMonth)
{
sMonth = aMonth[lGetMonth(dt) - 1];
}
else
{
sMonth = aMonth[lGetMonth(dt)];
}
//Format Day
sDay10 = a10[iDay / 10];
sDay1 = aDigi[(iDay % 10)];
sDay = sDay10 + sDay1;
if (iDay == 10) sDay = "初十";
if (iDay == 20) sDay = "二十";
if (iDay == 30) sDay = "三十";
//Format Lunar Date
//sLuniSolarDate = dtYear+"年"+dtMonth+"月"+dtDay+"日 "+Weeks(dtDayOfWeekToString())+" 农历" + sYear + "年" + sMonth + sDay;
sLuniSolarDate =" 农历" + sMonth + sDay;
return sLuniSolarDate;
}
private string Weeks(string Weeken)
{
switch (Weeken)
{
case "Monday":
return "星期一";
break;
case "Tuesday":
return "星期二";
break;
case "Wednesday":
return "星期三";
break;
case "Thursday":
return "星期四";
break;
case "Friday":
return "星期五";
break;
case "Saturday":
return "星期六";
break;
case "Sunday":
return "星期日";
break;
default:
return " ";
}
}
}
二、第二步
chinaDate s = new chinaDate();
Label1Text = DateTimeNowToShortDateString() + " " + CaculateWeekDay(DateTimeNowDayOfWeekToString()) + " " + scDate();
三、第三步
#region 得到今天是星期几
protected string CaculateWeekDay(string week)
{
string weekstr = "";
switch (week)
{
case "Monday": weekstr = "星期一"; break;
case "Tuesday": weekstr = "星期二"; break;
case "Wednesday": weekstr = "星期三"; break;
case "Thursday": weekstr = "星期四"; break;
case "Friday": weekstr = "星期五"; break;
case "Saturday": weekstr = "星期六"; break;
case "Sunday": weekstr = "星期日"; break;
}
return weekstr;
}
#endregion
#include<stdioh>
int main()
{int y, m, d, w;
scanf("%d %d %d", &y,&m,&d);
if(3 > m)
{m+= 12;
y--;}
w=((d+2m+3(m+1)/5+y+y/4-y/100+y/400)%7+1)%7;
printf("%d",w);
return 0;
}
c语言输入1到7输出星期几的方法如下
输入1-7之间的一个整数,然后根据输入的数字判断是星期几,最后输出对应的星期的全称。如输入4,则输出Thursday
#include
int_main(int_argc,charargv[])﹛int_a
printf("输入1-7的整数")
scanf("%d",&a)
switch(a)
﹛
case_1printf("Monday\n")break
case_2printf("Tuesday\n")break
case_3printf("wednesday\n")break
case_4printf("Thursday\n")break
case_5printf("Friday\n")break
case_6printf("saturday\n")break
case_7printf("Sunday\n")break
﹜
return_0
﹜
以上就是关于C# 中 怎样获得当前星期以及农历时间全部的内容,包括:C# 中 怎样获得当前星期以及农历时间、C语言 给出年月日 求出时星期几、c语言输入1到7输出星期几等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)