在.net中获取所选月份的所有日期和日期 [英] Get all days and dates of selected month in .net

查看:111
本文介绍了在.net中获取所选月份的所有日期和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我 如何所有天< span class =code-keyword>和  date   所选月份日历的code-keyword>  .net.This     创建出勤 员工。 

我每天都需要 date 所选月份 标签框中显示喜欢 sun,mon,tue等... 1 2 3 .... 28 29 30 31 基于 我选择的年。
谢谢 advance。

解决方案

一个简单的循环吧就够了,例如

  const   int  MONTH =  5 ;  //  写出2015年5月的所有日子 
DateTime dt = new DateTime( 2015 ,MONTH, 1 );
while (dt.Month == MONTH)
{
Console.WriteLine(dt.ToString( ddd dd));
dt = dt.AddDays( 1 );
}


你可以使用这种方法



  public 列表< datetime> GetDates( int  year, int  month)
{
return Enumerable.Range( 1 ,DateTime.DaysInMonth(year,month))
// 天数:1,2 ... 31等。
。选择(day = > new 日期时间(年,月,日))
// 每天将日期映射到日期
.ToList(); // 将日期加载到列表中
}


Can anyone please tell me how to get all days and date of selected month from calendar in .net.This is to create attendance of employees.

I need each days and date of the selected month to be displayed in label box.Like sun,mon,tue etc ...and 1,2,3....28 or 29 or 30 or 31  based on the month and year I selected.
Thanks in advance.

解决方案

A simple loop it is just enough, e.g.

const int MONTH = 5; // write out all the days of May 2015
DateTime dt = new DateTime(2015, MONTH, 1);
while (dt.Month == MONTH)
{
  Console.WriteLine(dt.ToString("ddd dd"));
  dt = dt.AddDays(1);
}


You can use this method

public List<datetime> GetDates(int year, int month)
{
   return Enumerable.Range(1, DateTime.DaysInMonth(year, month))
                      // Days: 1, 2 ... 31 etc.
                    .Select(day => new DateTime(year, month, day)) 
                     // Map each day to a date
                    .ToList(); // Load dates into a list
}


这篇关于在.net中获取所选月份的所有日期和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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