vb.net 中的日期格式和添加日期
我正在尝试向检索到的日期添加一天,如下所示
//reading fromdatabase
Dim expenddt_ As String = rdr("Expected_End_Date").ToString
Dim dt_1 As Date = Date.Parse(expenddt_)
Dim expenddt As String = dt_1.ToShortDateString()
txtenddt.Text = expenddt
假设如果 expenddt_
值为 "11/1/2012 12:00:00 AM",则 < code>dt_1 的值为 #11/1/2012# 并且 expenddt
的值为“11/1/2012”,因此在文本框 txtenddt
中,值显示为 expenddt
。
现在,当我尝试向 dt_1 添加一天时,
Dim test As Date = dt_1.AddDays(+1)
测试中的值是 11/2/2012,即添加一个月而不是一天。我如何添加一天?有人可以帮助我解决这个问题吗?
I am trying to add a day to a date retrieved as below
//reading fromdatabase
Dim expenddt_ As String = rdr("Expected_End_Date").ToString
Dim dt_1 As Date = Date.Parse(expenddt_)
Dim expenddt As String = dt_1.ToShortDateString()
txtenddt.Text = expenddt
Suppose if expenddt_
the value comes as "11/1/2012 12:00:00 AM", than dt_1
has the value #11/1/2012# and expenddt
has "11/1/2012" so in textbox txtenddt
the value appears as expenddt
.
Now when i try to add a day to dt_1
as
Dim test As Date = dt_1.AddDays(+1)
Than the value in test comes as 11/2/2012, i.e a month gets added and not the day. How can i add a day?can anyone help me with this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个简单的示例:
源
here is a simple example:
SOURCE
好吧,谢谢你们。我将日期解析为 mm//dd/yyyy 格式,然后添加了一天。当我发布这个问题时,我无法将日期解析为 mm/dd/yyyy 格式。现在我做到了,这个问题就解决了。
Well, tahnk you guys . i parsed The date to mm//dd/yyyy format and than added a day to it. When i posted this question i was unable to parse the date to mm/dd/yyyy format. Now i did it and this question is solved.
我认为您的输出格式是 MM/DD/YYYY,因此您可以尝试 dt_1.ToString("dd/MM/yyyy") 以您期望的格式查看内容。
您还可以检查 Day 属性。
I think your output format is MM/DD/YYYY, so you can try dt_1.ToString("dd/MM/yyyy") to see the content in the format you expected.
You can also check the Day property.