简体   繁体   English

无法将String转换为DateTIme

[英]Can't convert String to DateTIme

My Date Format : 12/30/2014 12:00:00 AM (MM/dd/yyyy) and I have a string rep as 我的日期格式:12/30/2014 12:00:00 AM(MM / dd / yyyy)我有一个字符串代表作为

String DateOfIssue = "12/30/2014 12:00:00 AM";

DateTime DOI = DateTime.ParseExact((DateOfIssue).Trim(), "MM/dd/yyyy HH:mm:ss tt", CultureInfo.GetCultureInfo("en-GB"));

but it is throwing exception. 但它是抛出异常。 I have seen a lot of posts on SO but none is working. 我在SO上看过很多帖子,但都没有。 What am I doing wrong ? 我究竟做错了什么 ? Please help and point my error. 请帮助并指出我的错误。 I have tried en-US also but that is also not working. 我也试过en-US,但那也行不通。

when I remove tt every thing works fine. 当我删除tt每件事情都很好。

HH -为24小时格式,请使用hh代替:

DateTime DOI = DateTime.ParseExact((DateOfIssue).Trim(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-GB"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM