获取系统时间

    /// <summary>
    /// 获取当前系统的全部时间(年/月/日 小时:分钟:秒); 要在Update中调用方法; 
    /// </summary>
    /// <returns>返回值(当前系统的全部时间)</returns>
    public static string Time_Now()
    {
        string sr = DateTime.Now.ToString();
        return sr;
    }
    /// <summary>
    /// 获取当前系统的日期(年,月,日);要在Update中调用;
    /// </summary>
    /// <param name="year">年;/;-</param>
    /// <param name="month">月;/;-<</param>
    /// <param name="day">日;/;-<</param>
    /// <returns>返回值(当前系统的日期)</returns>
    public static string Current_date(string year="/", string month = "/", string day = "")
    {
        string sr = string.Format("{0:D2}" + year + "{1:D2}" + month + "{2:D2}" + day, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
        return sr;
    }
    /// <summary>
    /// 获取当前系统的日期(年,月)
    /// </summary>
    /// <param name="year">年;/;-</param>
    /// <param name="month">月;/;-<</param>
    /// <returns>返回值(当前系统的日期)</returns>
    public static string Month_date(string year = "/", string month = "")
    {
        string sr = string.Format("{0:D2}" + year + "{1:D2}" + month, DateTime.Now.Year, DateTime.Now.Month);
        return sr;
    }
    /// <summary>
    /// 获取当前系统的日期(日)
    /// </summary>
    /// <param name="day">日;/;-<</param>
    /// <returns>返回值(当前系统的日期)</returns>
    public static string Day_date(string day = "")
    {
        string sr = string.Format("{0:D2}" + day, DateTime.Now.Day);
        return sr;
    }
    /// <summary>
    /// 获取当前系统的时间(小时,分钟,秒)
    /// </summary>
    /// <returns>返回值(当前系统的时间)</returns>
    public static string Current_Time()
    {
        string sr = string.Format("{0:D2}:{1:D2}:{2:D2}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
        return sr;
    }

    /// <summary>
    /// 获取当前系统的时间(星期)
    /// </summary>
    /// <returns>返回值(当前系统的时间)</returns>
    public static string Week_date()
    {
        string weekstr = DateTime.Now.DayOfWeek.ToString();
        switch (weekstr)
        {
            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;
    }
    /// <summary>
    /// 日期数据获取
    /// </summary>
    /// <param name="dayCount"></param>
    /// <returns></returns>
    public static List<string> RefreshData(int dayCount)
    {
        int year = DateTime.Now.Year;
        int month = DateTime.Now.Month;
        int day = DateTime.Now.Day;
        List<string> dayDatas = new List<string>(30);
        for (int i = 0; i < dayCount; i++)
        {
            string dayData;
            if (day > 0)
            {
                dayData = string.Format("{0:D2}" + "." + "{1:D2}", month, day--);
            }
            else
            {
                if (month - 1 > 0)
                {
                    month--;
                }
                else
                {
                    month = 12;
                    year--;
                }
                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    day = 31;
                }
                else if (i == 2)
                {
                    day = 29;
                }
                else
                {
                    day = 30;
                }
                dayData = string.Format("{0:D2}" + "." + "{1:D2}", month, day--);
            }
            dayDatas.Add(dayData);
        }
        return dayDatas;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值