C\#달력 을 간단하게 출력 하 는 방법
C\#로 달력 을 출력 합 니 다.이 기능 은 계획 일정 과 관련 된 내용 을 Ajax 방식 으로 표시 할 수 있 습 니 다.C\#출력 을 제어 하기 때문에 필요 한 업무 처리 논 리 를 쉽게 추가 할 수 있 습 니 다.
1.콘 솔 출력:
using System;
namespace
{
class Program
{
public static void Main(string[] args)
{
string s = " ";
Console.WriteLine(" :");
int nYear = int.Parse(Console.ReadLine());
Console.WriteLine(" :");
int nMonth = int.Parse(Console.ReadLine());
DateTime day1 = new DateTime(nYear,nMonth,1);
Console.WriteLine("{0}/{1}",day1.Year,day1.Month);
Console.WriteLine(" ");
int week1 =(int )day1.DayOfWeek;// 1
//Console.WriteLine(" {0}",week1);
int lastday = day1.AddMonths(1).AddDays(-1).Day; //
for (int i = 0; i < week1; i++)
Console.Write(s);//
for (int i = 1; i <= lastday; i++)
{
Console.Write("{0:00} ", i);// 01 02
if ((i + week1) % 7 == 0)
Console.WriteLine();
}
Console.WriteLine();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
효과 그림:2.Html 표 출력:
#region
/// <summary>
/// index: ,
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public static string GetCalendarHtml(int index = 0)
{
DateTime day1 = new DateTime(DateTime.Now.AddMonths(index).Year, DateTime.Now.AddMonths(index).Month, 1);
int week1 = (int)day1.DayOfWeek;// 1
int lastday = day1.AddMonths(1).AddDays(-1).Day; //
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append(string.Format("<table class='calendar_table'><caption><span style='cursor:pointer' class='prevMonth' onclick='javascript:changeMonth(-1)'> </span><span class='currMonth'> {0} {1} </span><span style='cursor:pointer' class='nextMonth' onclick='javascript:changeMonth(1)'> </span></caption>", DateTime.Now.AddMonths(index).Year, DateTime.Now.AddMonths(index).Month));
builder.Append("<tr class='calendar_head'>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("<td class='calendar_cell'> </td>");
builder.Append("</tr>");
string emptyString = "<td class='calendar_cell'> </td>";
if (week1 > 0)
{
builder.Append("<tr class='calendar_body'>");
for (int i = 0; i < week1; i++)
{
builder.Append(emptyString);
}
}
for (int i = 1; i <= lastday; i++)
{
string day = string.Format("{0:00} ", i);// 01 02
builder.Append(string.Format("<td class='calendar_cell'>{0}</td>", day));
if ((i + week1) % 7 == 0)
{
builder.Append("</tr><tr class='calendar_body'>");
}
}
builder.Append("</tr>");
builder.Append("</table>");
return builder.ToString();
}
#endregion
본 고 에서 말 한 것 이 여러분 의 C\#프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.