您好我想以前一天的Y-m-d 20:00:00格式设置变量日期。有人可以帮忙吗?
答案 0 :(得分:3)
Dim lastNight As DateTime = DateTime.Today.AddHours(-4)
Dim lastNightString As String = lastNight.ToString("y-M-d HH:mm:ss")
答案 1 :(得分:0)
尝试
Dim lastEvening as DateTime = DateTime.Today.AddDays(-1).AddHours(20)
按要求格式化
Dim formattedLastEvening as string = lastEvening.ToString("y-M-d HH:mm:ss")
答案 2 :(得分:0)
可能有一种更简单的方法,但这就是我在C#中可能会这样做的方式:
DateTime myDate = DateTime.Today.AddHours(20 - DateTime.Today.Hour).AddMinutes(0 - DateTime.Today.Minute).AddSeconds(0 - DateTime.Today.Second).AddMilliseconds(0 - DateTime.Today .Millisecond);
然后格式化找到以下内容: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx