如何增加月份和年份 [英] How to increment month and Year

查看:95
本文介绍了如何增加月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串变量

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,然后对其进行数学计算.
由于这是您功课的主要内容,因此我不会给您任何代码,而是请查看 DateTime.ToString [
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


这篇关于如何增加月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆