C#datetime对象 [英] C# datetime objects

查看:71
本文介绍了C#datetime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始日期= 2013年8月15日,结束日期= 09/11 / 2013.Loop开始和结束并显示之间的所有日期。







例如





08/15/2013

08/16/2013

08/17/2013



















09/11/2013



谢谢并且关于

解决方案

可以将TimeSpan添加到DateTime对象。

这是使用列表框执行此操作的一种方法:

  private   void  FillDateList()
{
DateTime start = new DateTime( 2013 8 15 );
DateTime end = new DateTime( 2013 11 9 );
TimeSpan oneday = new TimeSpan( 1 0 0 0 );
while (start < = end)
{
< span class =code-keyword> this .listBox1.Items.Add(start.ToShortDateString());
start = start + oneday;
}
}


听起来像家庭作业。



有一个查看 TimeRanger - 允许在一段时间内进行预告 [ ^ ]

start date=08/15/2013, end date=09/11/2013.Loop through start and end and display all the dates between.



for example


08/15/2013
08/16/2013
08/17/2013
.
.
.
.
.
.
.
.
.
09/11/2013

thanks and regards

解决方案

TimeSpan can be added to DateTime objects.
Here's one way to do it using a list box:

private void FillDateList()
        {
            DateTime start = new DateTime(2013, 8, 15);
            DateTime end = new DateTime(2013, 11, 9);
            TimeSpan oneday = new TimeSpan(1, 0, 0, 0);
            while (start <= end)
            {
                this.listBox1.Items.Add(start.ToShortDateString());
                start = start + oneday;
            }
        }


Sounds like homework.

Have a look at TimeRanger -- Allows foreaching across a time interval[^]


这篇关于C#datetime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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