我收到日期转换错误,请帮帮我。谢谢大家。
protected void getdate(object sender, EventArgs e)
{
DateTime dt2 = Convert.ToDateTime(txtdate.Text);
DateTime dt3 = dt2.AddDays(9);
txtlastdate.Text = dt3.ToString();
}
答案 0 :(得分:0)
您可以使用datetime.ParseExact,您可以手动管理yyyyMMddHHmmss格式;
DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
答案 1 :(得分:-1)
尝试添加格式 喜欢这个来自msdn的链接: https://msdn.microsoft.com/en-us/library/zdtaw1bw(v=vs.110).aspx
示例来自格式
的链接using System;
using System.Globalization;
using System.Threading;
public class Example
{
public static void Main()
{
String[] formats = { "G", "MM/yyyy", @"MM\/dd\/yyyy HH:mm",
"yyyyMMdd" };
String[] cultureNames = { "en-US", "fr-FR" };
DateTime date = new DateTime(2015, 8, 18, 13, 31, 17);
foreach (var cultureName in cultureNames) {
var culture = new CultureInfo(cultureName);
CultureInfo.CurrentCulture = culture;
Console.WriteLine(culture.NativeName);
foreach (var format in formats)
Console.WriteLine(" {0}: {1}", format,
date.ToString(format));
Console.WriteLine();
}
}
}
// The example displays the following output:
// English (United States)
// G: 8/18/2015 1:31:17 PM
// MM/yyyy: 08/2015
// MM\/dd\/yyyy HH:mm: 08/18/2015 13:31
// yyyyMMdd: 20150818
//
// français (France)
// G: 18/08/2015 13:31:17
// MM/yyyy: 08/2015
// MM\/dd\/yyyy HH:mm: 08/18/2015 13:31
// yyyyMMdd: 20150818