以下のコードは、日付のテキストを抽出し、それを変換するのに失敗した - それは私がこれまで試したものです:日付文字列の一部を抽出するように、正規表現パターンを作成し、どのようにこれを変換する方法どのようにこの日付文字列を抽出し、C#と正規表現を使用してDateTimeに変換しますか?
var inputText = "some words 2012-01-06 13-32-40 some words";
string pattern = "d{4}-d{2}-d{2} d{4}-d{2}-d{2}";
var regex = new Regex(pattern);
Match match = regex.Match(inputText);
// it should find the "2012-01-06 13-32-40" text
DateTime result;
if (match.Success)
{
result = DateTime.Parse(match.Value);
}
文字列をDateTimeに変換しますか?
私が試した:
IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
result = DateTime.ParseExact(match.Value, "yyyy-MM-dd hh-mm-ss", theCultureInfo);
おかげで、
何を試しましたか?どのような正確にあなたは困難を抱えていますか?可能な入力と期待される出力の**例**を投稿してください。 – Oded