如何增加月份和年份
问题描述:
我有一个字符串变量
I have a string variable
Dim SHG As String
SHG = "FILENAME" + "_" + "Jan12"
这里的文件名是常量,而Jan12不是固定的.
在这里,我想将此数值降低到13,14,15 ..等,与月份相同,如jan,feb,march,april,may,june,july,aug .... dec
我怎样才能使Thie保持沉默并将其存储在变量中.
我想要这样
Jan12,Feb12 ...,Jan13,Feb13 ...
此帖子的发布解决方案
在此先感谢
代码块-已添加.选中将我的内容视为纯文本..."-删除. LOSMAC [/EDIT]
Here the File name is constant and the Jan12 is not a fixed one.
Here i want to increament this to 13,14,15.. and etc and same as month also like jan,feb,march,april,may,june,july,aug .... dec
how can i increament thie and store in a variable.
I want like this
Jan12,Feb12...,Jan13,Feb13...
Post Solution for this post
Thanks in advance
COde block - added. Check "Treat my content as plain text..." - removed. LOSMAC[/EDIT]
答
Don''t.
而是将其存储为DateTime,然后对其进行数学计算.
由于这是您功课的主要内容,因此我不会给您任何代码,而是请查看 ^ ]和 ^ ]
Don''t.
Store it instead as a DateTime, and do the math on that.
Since this smells heavily of your homework, I won''t give you any code, but look at DateTime.TryParseExact[^] and DateTime.ToString[^]
如何枚举日期?
How to enum dates?
Sub Main()
Dim sFileName As String = String.Empty
Dim dStart As DateTime = Nothing
Dim dEnd As DateTime = Nothing
Dim dDay As DateTime = Nothing
dStart = New Date(2012, 1, 1)
dEnd = New Date(2012, 12, 31)
dDay = dStart
Do While (dDay <= dEnd)
sFileName = "filename_" & Microsoft.VisualBasic.Format(dDay, "MMMdd")
Console.WriteLine(sFileName)
dDay = dDay.AddDays(1)
Loop
Console.ReadKey()
End Sub