zoukankan      html  css  js  c++  java
  • c#实现输出本月的月历

    效果如图:

    代码如下:

    namespace WebForm
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                PrintCalender(2016, 10);
            }
    
            public static void PrintCalender(int year, int month)
            {
                formatDate fd = new formatDate(year, month);
                string calender =
     @"日 一 二 三 四 五 六
    {0} {0} {0} {0} {0} {0} {0}
    {0} {0} {0} {0} {0} {0} {0}
    {0} {0} {0} {0} {0} {0} {0}
    {0} {0} {0} {0} {0} {0} {0}
    {0} {0} {0} {0} {0} {0} {0}
    {0} {0} {0} {0} {0} {0} {0}";
                calender = string.Format(calender, fd).TrimEnd();
                HttpContext.Current.Response.Write(calender);
            }
        }
        
        public class formatDate : IFormattable
        {
            int num;
            int max;
            public formatDate(int year, int month)
            {
                DateTime dt = new DateTime(year, month, 1);
                num = (int)dt.DayOfWeek * -1;
                max = DateTime.DaysInMonth(year, month);
            }
            public string ToString(string format, IFormatProvider formatProvider)
            {
                return num++ < 0 || num > max ? "  " : num.ToString("00");
            }
        }
    }
  • 相关阅读:
    比特币and区块链
    C#汽车租赁系统 完整版
    C#托盘程序设置
    网络电视精灵项目
    C#文件操作 File(静态类)
    深入解读XML解析
    ListView 控件总结
    DataGridView 的使用总结
    动态添加节点
    IrisSkin2.dll 添加皮肤
  • 原文地址:https://www.cnblogs.com/jronny/p/5999862.html
Copyright © 2011-2022 走看看