function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008 num=num+""; var date=""; var month=new Array(); month["Jan"]=1;month["Feb"]=2;month["Mar"]=3;month["Apr"]=4;month["May"]=5;month["Jan"]=6; month["Jul"]=7;month["Aug"]=8;month["Sep"]=9;month["Oct"]=10;month["Nov"]=11;month["Dec"]=12; var week=new Array(); week["Mon"]="一";week["Tue"]="二";week["Wed"]="三";week["Thu"]="四"; week["Fri"]="五";week["Sat"]="六";week["Sun"]="日"; str=num.split(" "); date=str[5]+"年"; date=date+month[str[1]]+"月"+str[2]+"日 "+str[3]; date=date+" 周"+week[str[0]]; return date; }
CultureInfo enUS = new CultureInfo("en-US"); string dateString; DateTime dateValue;// Parse date with no style flags. dateString = " 5/01/2009 8:30 AM"; try { dateValue = DateTime.ParseExact(dateString, "g", enUS, DateTimeStyles.None); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); } // Allow a leading space in the date string. try { dateValue = DateTime.ParseExact(dateString, "g", enUS, DateTimeStyles.AllowLeadingWhite); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); }// Use custom formats with M and MM. dateString = "5/01/2009 09:00"; try { dateValue = DateTime.ParseExact(dateString, "M/dd/yyyy hh:mm", enUS, DateTimeStyles.None); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); } // Allow a leading space in the date string. try { dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm", enUS, DateTimeStyles.None); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); }// Parse a string with time zone information. dateString = "05/01/2009 01:30:42 PM -05:00"; try { dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.None); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); } // Allow a leading space in the date string. try { dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.AdjustToUniversal); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); }// Parse a string represengting UTC. dateString = "2008-06-11T16:11:20.0904778Z"; try { dateValue = DateTime.ParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.None); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); } try { dateValue = DateTime.ParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue, dateValue.Kind); } catch (FormatException) { outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString); }
{ //Fri Oct 31 18:00:00 UTC+0800 2008
num=num+"";
var date="";
var month=new Array();
month["Jan"]=1;month["Feb"]=2;month["Mar"]=3;month["Apr"]=4;month["May"]=5;month["Jan"]=6;
month["Jul"]=7;month["Aug"]=8;month["Sep"]=9;month["Oct"]=10;month["Nov"]=11;month["Dec"]=12;
var week=new Array();
week["Mon"]="一";week["Tue"]="二";week["Wed"]="三";week["Thu"]="四"; week["Fri"]="五";week["Sat"]="六";week["Sun"]="日";
str=num.split(" ");
date=str[5]+"年";
date=date+month[str[1]]+"月"+str[2]+"日 "+str[3];
date=date+" 周"+week[str[0]];
return date;
}
string dateString;
DateTime dateValue;// Parse date with no style flags.
dateString = " 5/01/2009 8:30 AM";
try
{
dateValue = DateTime.ParseExact(dateString, "g", enUS, DateTimeStyles.None);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}
// Allow a leading space in the date string.
try
{
dateValue = DateTime.ParseExact(dateString, "g", enUS, DateTimeStyles.AllowLeadingWhite);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}// Use custom formats with M and MM.
dateString = "5/01/2009 09:00";
try
{
dateValue = DateTime.ParseExact(dateString, "M/dd/yyyy hh:mm", enUS, DateTimeStyles.None);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}
// Allow a leading space in the date string.
try
{
dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm", enUS, DateTimeStyles.None);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}// Parse a string with time zone information.
dateString = "05/01/2009 01:30:42 PM -05:00";
try
{
dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.None);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}
// Allow a leading space in the date string.
try
{
dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS,
DateTimeStyles.AdjustToUniversal);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}// Parse a string represengting UTC.
dateString = "2008-06-11T16:11:20.0904778Z";
try
{
dateValue = DateTime.ParseExact(dateString, "o", CultureInfo.InvariantCulture,
DateTimeStyles.None);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}
try
{
dateValue = DateTime.ParseExact(dateString, "o", CultureInfo.InvariantCulture,
DateTimeStyles.RoundtripKind);
outputBlock.Text += String.Format("Converted '{0}' to {1} ({2}).\n", dateString, dateValue,
dateValue.Kind);
}
catch (FormatException)
{
outputBlock.Text += String.Format("'{0}' is not in an acceptable format.\n", dateString);
}
string str = DateTime.ParseExact("Mon Oct 27 01:10:01 UTC+0800 2008", "ddd MMM dd HH:mm:ss UTCzzz yyyy",new System.Globalization.CultureInfo("en-US")).ToString("yyyy-MM-dd HH:mm:ss");