Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将dd/MM/yyyy hh:MM am/pm转换为MM/dd/yyyy hh:MM am/pm_C#_Asp.net_.net_Datetime - Fatal编程技术网

C# 将dd/MM/yyyy hh:MM am/pm转换为MM/dd/yyyy hh:MM am/pm

C# 将dd/MM/yyyy hh:MM am/pm转换为MM/dd/yyyy hh:MM am/pm,c#,asp.net,.net,datetime,C#,Asp.net,.net,Datetime,我想将字符串:24/11/2016 04:30 pm转换为日期时间值:11/24/2016 04:30 pm 我的代码是: DateTime date = DateTime.ParseExact("24/11/2016 04:30 pm", "dd/MM/yyyy hh:mm aa", CultureInfo.InvariantCulture); 但我有一个错误: 字符串未被识别为有效的日期时间 我能做什么?对于AM/PM指示器,您必须使用tt而不是aa: DateTime date=Date

我想将字符串:
24/11/2016 04:30 pm
转换为日期时间值:
11/24/2016 04:30 pm

我的代码是:

DateTime date = DateTime.ParseExact("24/11/2016 04:30 pm", "dd/MM/yyyy hh:mm aa", CultureInfo.InvariantCulture);
但我有一个错误:

字符串未被识别为有效的日期时间


我能做什么?

对于AM/PM指示器,您必须使用
tt
而不是
aa


DateTime date=DateTime.ParseExact(“2016年11月24日下午4:30”,“dd/MM/yyyy hh:MM tt”,CultureInfo.InvariantCulture)Tks@Pikoh。我明白了。
ParseExact
一如既往地拯救世界:)天哪。这很容易。非常感谢。
DateTime date = DateTime.ParseExact("24/11/2016 04:30 pm", "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);