如何将字符串“00:05:06,607”转换为日期时间?

How to convert string "00:05:06,607" to DateTime?

var time = "00:05:06,607";
string pattern = "hh:mm:ss,fff";
DateTime.TryParseExact(time, pattern, null, DateTimeStyles.None, out parsedTime);

但是 TryParseExact 函数返回了我 false。我还尝试了 TryParse 函数,例如:

DateTime.TryParse(time, out parsedTime);

在我将时间更改为 "00:05:06.607" 之前也返回 false。但是我的源日期有很多行,例如 "hh:mm:ss,fff"

有人可以帮忙吗?

这是 github 上的完整项目 https://github.com/DeronLee/PhoneBook/blob/master/subtitle/MakeSubtitle.cs

试试这个

DateTime dateTime = DateTime.ParseExact(time, pattern ,CultureInfo.InvariantCulture);

我文件中的源数据是中文字幕文件。我想也许它使用中文逗号而不是逗号,所以这就是为什么我的代码不起作用但你的。

好的。 终于。不是逗号。 space。我必须先使用 trim() 。 添加 trim 函数后效果很好