zoukankan      html  css  js  c++  java
  • 日期显示月日

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication2
    {
        public class Program
        {
            public static void Main()
            {
                testTime t = new testTime();
                string time = t.returnTime(Convert.ToDateTime("1990-01-05"), Convert.ToDateTime("1990-02-14"));
                Console.WriteLine(time);
                Console.Read();
            }
        }
        public class testTime
        {
            public string returnTime(DateTime beginTime, DateTime endTime)
            {
                System.Text.StringBuilder timeAppend = new StringBuilder();
                for (int month = beginTime.Month; month <= endTime.Month; month++)
                {
                    //判断该月份几天
                    int idate = System.DateTime.DaysInMonth(beginTime.Year, month);
                    //判断是否是同月
                    if (beginTime.Month == endTime.Month)
                    {
                        for (int day = beginTime.Day; day <= endTime.Day; day++)
                        {
                            timeAppend.Append(month + "月" + day + "日,");
                        }
                    }
                    //如果说是起始月份
                    else if (month == beginTime.Month)
                    {
                        for (int day = beginTime.Day; day <= idate; day++)
                        {
                            timeAppend.Append(month + "月" + day + "日,");
                        }
                    }
                   //如果是结束月份
                    else if (month == endTime.Month)
                    {
                        for (int day = 1; day <= endTime.Day; day++)
                        {
                            timeAppend.Append(month + "月" + day + "日,");
                        }
                    }
                    //其它就从1号到本月的天数
                    else
                    {
                        for (int day = 1; day <= idate; day++)
                        {
                            timeAppend.Append(month + "月" + day + "日,");
                        }
                    }
                }
                return timeAppend.ToString();
            }
        }
    }

  • 相关阅读:
    向量旋转公式推导
    atan函数与atan2函数
    UVALive 7040 Color (容斥原理+逆元+组合数+费马小定理+快速幂)
    关于source insight、添加.s和.S文件,显示全部路径、加入项目后闪屏幕
    linux内核设计与实现--进程调度 系统调用
    linux内核设计与实现--进程管理
    linux命令行与shell脚本编程大全---bash shell命令
    linux内核设计与实现--从内核出发
    Linux内核学习之路
    NAND FLASH均衡算法笔记(转)
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/1743776.html
Copyright © 2011-2022 走看看