yyyyMMdd
形式の日付を含む文字列をmm-dd-yyyy
DateTime形式に変換したい。どうすれば入手できますか?
var dateString = "20050802";
var date = myDate = DateTime.ParseExact(dateString,
"yyyyMMdd",
System.Globalization.CultureInfo.InvariantCulture);
public static DateTime ConvertDate(string date, string pattern)
{
DateTime retval = DateTime.MinValue;
if (System.DateTime.TryParseExact(date, pattern, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out retval))
return retval;
// Could not convert date..
return DateTime.MinValue;
}
DateTime myDate = ConvertDate("20101230", "yyyyMMdd");
CultureInfo provider = CultureInfo.CreateSpecificCulture("en-UK");
string dateString = "19850121"; //in yyyyMMdd format
string oldFormat = "yyyyMMdd";
DateTime result = DateTime.ParseExact(dateString, oldFormat, provider); //MM/dd/yyyyformat