Check this link for more info:-
http://msdn.microsoft.com/en-us/library/9xk1h71t.aspx
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
Console.WriteLine("{0,-18}{1,-12}{2}\n", "Date String", "Culture", "Result");
string[] cultureNames = { "en-US", "ru-RU","ja-JP" };
string[] dateStrings = { "01/02/09", "2009/02/03", "01/2009/03",
"01/02/2009", "21/02/09", "01/22/09",
"01/02/23" };
// Iterate each culture name in the array.
foreach (string cultureName in cultureNames)
{
CultureInfo culture = new CultureInfo(cultureName);
// Parse each date using the designated culture.
foreach (string dateStr in dateStrings)
{
DateTime dateTimeValue;
try {
dateTimeValue = Convert.ToDateTime(dateStr, culture);
// Display the date and time in a fixed format.
Console.WriteLine("{0,-18}{1,-12}{2:yyyy-MMM-dd}",
dateStr, cultureName, dateTimeValue);
}
catch (FormatException e) {
Console.WriteLine("{0,-18}{1,-12}{2}",
dateStr, cultureName, e.GetType().Name);
}
}
Console.WriteLine();
}
}
}
仅供参考:不是写的'的Response.Write(年+ “+ +月+”“+日+”“+小时+”“+分);',它'打赌这样做:'Response.Write(string.Format(“{0} {1} {2} {3} {4} 0”,year,month,day,hour,min));' – 2010-09-22 17:06:46
第一个例子应该管用。你确定你把它正确地复制了吗? Response.Write只写入5个值,打印注释显示6个。 – Brandon 2010-09-22 17:06:55
可以在失败时发布'toParse'的值和'dt.ToString()'的值吗? – 2010-09-22 17:27:46