C#转换字符串“ yyyy-mm-dd HH:MM:SSSSSSSSSS”到目前为止
I have a string, as an example: "2022-04-17 14:46:31 UTC"
And I want to convert it to date time but I have got the following error:
字符串'2022-04-17 14:46:31 UTC'未被认为是有效的 dateTime.s有一个未知的单词,从索引'20'开始。
Notice that I have tried:
var date = DateTime.Parse("2022-04-17 14:46:31 UTC");
and
DateTime dt;
DateTime.TryParseExact("2022-04-17 14:46:31 UTC",
"yyyy-MM-dd hh:mm:ss 'UTC'",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)
I have a string, as an example: "2022-04-17 14:46:31 UTC"
And I want to convert it to date time but I have got the following error:
The string '2022-04-17 14:46:31 UTC' was not recognized as a valid
DateTime.There is an unknown word starting at index '20'."
Notice that I have tried:
var date = DateTime.Parse("2022-04-17 14:46:31 UTC");
and
DateTime dt;
DateTime.TryParseExact("2022-04-17 14:46:31 UTC",
"yyyy-MM-dd hh:mm:ss 'UTC'",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
continue
There are two things to be done:
HH
for the 24 hour format根据此答案您需要将时区名称转换为时移。
因此,要首先,我们需要获取时区名称表到时区移动。我将其复制在这里并转换为字典。
完整的算法是:
According to this answer you need to convert time zone name to time shift.
So to do it first we need to get table of time zone name to time zone shift. I copy it from here and convert to dictionary.
And the full algorithm is: