【问题标题】:display date from current dateto next six days显示从当前日期到接下来六天的日期
【发布时间】:2012-11-21 05:46:12
【问题描述】:

我正在使用此代码显示从当前日期到接下来六天的日期。 如果有这样的显示日期的其他代码。请帮忙

Private Sub Displaydate()
    cn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("DataConnectionString")
    lblDateday.Text = System.DateTime.Now.ToString("dddd")
    lblMonthdate.Text = System.DateTime.Now.ToString("dd MMMM ")
    lblDateday2.Text = System.DateTime.Now.AddDays(1).ToString("dddd")
    lblMonthdate2.Text = System.DateTime.Now.AddDays(1).ToString("dd MMMM ")
    lblDateday3.Text = System.DateTime.Now.AddDays(2).ToString("dddd")
    lblMonthdate3.Text = System.DateTime.Now.AddDays(2).ToString("dd MMMM ")
    lblDateday4.Text = System.DateTime.Now.AddDays(3).ToString("dddd")
    lblMonthdate4.Text = System.DateTime.Now.AddDays(3).ToString("dd MMMM ")
    lblDateday5.Text = System.DateTime.Now.AddDays(4).ToString("dddd")
    lblMonthdate5.Text = System.DateTime.Now.AddDays(4).ToString("dd MMMM ")
    lblDateday6.Text = System.DateTime.Now.AddDays(5).ToString("dddd")
    lblMonthdate6.Text = System.DateTime.Now.AddDays(5).ToString("dd MMMM ")
    lblDateday7.Text = System.DateTime.Now.AddDays(6).ToString("dddd")
    lblMonthdate7.Text = System.DateTime.Now.AddDays(6).ToString("dd MMMM ")
End Sub

输出是

周三周四周五周六周日周一周二

11 月 21 日 11 月 22 日 11 月 23 日 11 月 24 日 11 月 25 日 11 月 26 日 11 月 27 日

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    把你处理的东西放到数组中,然后做循环。

    全局分配列表

    Dim DateDayList as List(of Label) = new List(of Label)
    Dim MonthDayList as List(of Label) = new List(of Label)
    

    将所有 dateDay 标签以正确的顺序添加到 Initialize 子目录中。

    DateDayList.Add(lblDateDay)
    DateDayList.Add(lblDateDay2)
    etc.
    

    对月日标签执行相同操作。

    然后简单地这样做:

    for i as Integer = 0 To 6
       DateDayList(i).Text = System.DateTime.Now.AddDays(i).ToString("dddd")
       MonthDayList(i).Text = System.DateTime.Now.AddDays(i).ToString("dd MMMM ")
    next
    

    【讨论】:

      猜你喜欢
      • 2017-12-29
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 2016-11-29
      • 2019-06-01
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多