c#中字串轉換成日期

好記心不如亂筆頭,開發過程中,需要對頁面日期字串進行處理,如果轉換成日期類型後,對於天數或是月份的處理較為簡單。

特記錄字串轉換成日期格式方法,供日後查詢參考。

 

using System.Globalization;

string inStr = "201007"
string dateFormmat = "yyyyMM";

DateTime tranTime = DateTime.ParseExact(inStr,dateFormmat,new CultureInfo("zh-CN"), DateTimeStyles.AllowWhiteSpaces);

string outStr = tranTime.AddMonths(1).ToString("yyyyMM");

posted @ 2010-08-05 10:56  Leya  阅读(182)  评论(0编辑  收藏  举报