开发者

Get directory name based on current date

I have to get directory name made by following pattern: t开发者_开发百科wo last digits of a year concatenated with month number ( always two digits). For example directory from september 2010 would be "1009".

I did it but I found my code quite trashy. How can I improve it?

My current code:

    public string GetDirectoryNameFromDate(DateTime date)
    {
        StringBuilder sb = new StringBuilder();

        sb.Append(date.Year.ToString().Substring(2));

        int month = date.Month;
        if (month < 10)
        {
            sb.Append("0");
        }
        sb.Append(month.ToString());

        return sb.ToString();
    }

Thanks for advice!


This should be quite easy. Use

date.ToString("yyMM");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜