【问题标题】:vb.net DateTimePicker remove time 12:00:00 AMvb.net DateTimePicker 删除时间 12:00:00 AM
【发布时间】:2016-11-28 12:36:33
【问题描述】:

我在我的列表视图上查看日期时遇到问题。

在我的 SQL 上没关系,在我的列“2016-28-11”上没问题 但是当我在 vb.net 的列表视图中查看它时,它说“2016-28-11 12:00:00 am”

在我的日期时间选择器上

值:2016 年 11 月 28 日 自定义格式:yyyy-MM-dd 格式:自定义

当我保存日期时,它会添加那个时间。谁能帮帮我?

【问题讨论】:

  • 它没有添加时间。时间一直都在,它是DateTime 类型不可或缺的一部分。请理解一个值和它的字符串表示之间的区别。您为日期选择器选择的字符串表示对保存在数据库中的没有影响,将显示从数据库中读取的除非您特别要求使用其他格式,否则使用一些默认格式。
  • 保存数据时仅使用日期部分。 yourDateTimeValue.Date 返回时间值设置为午夜 00:00 的日期

标签: mysql vb.net date time


【解决方案1】:

当您在列表视图中添加日期时,只需使用类似的内容:

 Dim NewItem As New ListViewItem
 NewItem.Text = "My Item"
 NewItem.SubItems.Add(mydate.tostring("yyyy-MM-dd"))
 ListView1.Items.Add(NewItem)

请记住mydate.tostring("yyyy-MM-dd"),其中mydatedatetime

考虑你的cmets,这里是代码:

.SubItems.Add(ds.Tables("studnum").Rows(i).Item(4).ToString)
Dim MyDate As DateTime = CDate(ds.Tables("studnum").Rows(i).Item(5).ToString)
.SubItems.Add(MyDate.ToString("yyyy-MM-dd"))

【讨论】:

  • ListView 没有SubItems 属性,只有Items。另外,最后你有一个错字;你有一个额外的括号 ) 而不是双引号 "
  • @VisualVincent ehehe 感谢您提供的信息 :D 我在没有 Visual Studio 的情况下写错了
  • 对不起,伙计们,我刚接触这个。我尊重你所有的帖子,我收到一个错误,它说从字符串“yyyy-MM-dd”到类型“整数”的转换无效。 :(
  • @VAN 将您的代码发布到您遇到错误的地方,最好找到解决方案;)
  • For i As Integer = 0 To ds.Tables("studnum").Rows.Count - 1 With ListView1.Items.Add(ds.Tables("studnum").Rows(i)。 Item(0).ToString) .SubItems.Add(ds.Tables("studnum").Rows(i).Item(1).ToString) .SubItems.Add(ds.Tables("studnum").Rows(i ).Item(2).ToString) .SubItems.Add(ds.Tables("studnum").Rows(i).Item(3).ToString) .SubItems.Add(ds.Tables("studnum").Rows (i).Item(4).ToString) .SubItems.Add(ds.Tables("studnum").Rows(i).Item(5).ToString)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 2015-11-05
  • 2023-03-28
  • 2012-05-01
相关资源
最近更新 更多