字符串“yyyy-mm-dd HH:mm:ss”未被识别为有效的日期时间

问题描述 投票:0回答:1

我有一个如下所示的字符串:

string expiredDate = "2026-05-24 18:54:55";

我想使用下面的代码将其转换为日期时间格式:

DateTime myDate = DateTime.ParseExact(expiredDate, "dd MMMM yyyy HH:mm:ss", CultureInfo.InvariantCulture);

但是它不起作用,我收到此错误:

我也尝试过使用

替换它
DateTime expiredDate = DateTime.ParseExact(expiredDate, "dd MMMM yyyy HH:mm:ss", CultureInfo.CreateSpecificCulture("id-id"));

但我仍然遇到同样的错误。

如何解决?

c# string datetime uwp
1个回答
0
投票

那为什么不呢

DateTime myDate = DateTime.ParseExact(expiredDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
© www.soinside.com 2019 - 2024. All rights reserved.