如何获取特定月份内的日期名称 [英] How to get day Names within specific Month

查看:82
本文介绍了如何获取特定月份内的日期名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,所有

我的问题是我需要在一个月之内得到所有的日子

(即):当我将(3,2009)传递给函数时,得到类似
的结果
星期六1/3/3009
2009年2月3日星期日
2009年3月3日,星期一
------
------
----
------
2009年3月3日,星期五


heey all

my question is that i need to get all the days within amonth

(i.e) : when i pass (3,2009) to the function i get aresult like

saturday 1/3/3009
Sunday 2/3/2009
Monday 3/3/2009
------
------
----
------
Friday 31/3/2009


how this should be Done !!!!

推荐答案

我为您创建了一个函数,该函数可以为您提供当月所有日期的DateTime值数组! >
I created a function for you that gives you an array of DateTime values of all days within the month!

public DateTime[] GetAllDays(int year, int month)
{
    int days = DateTime.DaysInMonth(year, month);

    DateTime[] dates = new DateTime[days];

    for (int d = 0; d < days; d++)
    {
        dates[d] = new DateTime(year, month, (d + 1));
    }

    return dates;
}



要使用此功能,您应该执行以下操作:



To use this you should do:

DateTime[] dates = GetAllDays(2009, 3);

for(int d = 0; d < dates.Length; d++)
{
  textBox1.Text += dates[d].ToLongDateString() + Environment.NewLine;
}



结果:



Result:

Sunday, March 01, 2009
Monday, March 02, 2009
Tuesday, March 03, 2009
...
...
...
Tuesday, March 31, 2009


谢谢你非常

但是如何将此值存储在数据表列上?
Thank u very much

but how to store this values on datatable column ???


这篇关于如何获取特定月份内的日期名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆