在.NET中,您可以使用以下AddMonths
方法:@H_419_1@
@H_419_3@DateTime date = new DateTime(2013, 5, 19); DateTime newDate = date.AddMonths(14);
至于使用指定格式从字符串中解析日期,则可以使用以下TryParseExact
方法:@H_419_1@
@H_419_3@string dateStr = "19/05/2013"; DateTime date; if (DateTime.TryParseExact(dateStr, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { // successfully parsed the string into a DateTime instance => // here we Could add the desired number of months to it and construct // a new DateTime DateTime newDate = date.AddMonths(14); } else { // parsing Failed => the specified string was not in the correct format // you Could inform the user about that here }