简体   繁体   English

无法将ASP.NET MVC字符串识别为有效的DateTime

[英]ASP.NET MVC String was not recognized as a valid DateTime

I searched on the internet for a while now, but every answer i found, didn't worked for me. 我现在在互联网上搜索了一段时间,但是找到的每个答案都对我不起作用。

I am trying to convert a string to a datetime, but every time i try different things, i get the exeption: System.FormatException: 'String was not recognized as a valid DateTime. 我正在尝试将字符串转换为日期时间,但是每次尝试不同的操作时,都会得到例外:System.FormatException:'字符串未被识别为有效的DateTime。

string temp = Request.QueryString["begintijd"];
DateTime test = DateTime.ParseExact(temp, "dd/MM/yyyy", CultureInfo.InvariantCulture);

The value of temp is: 05/22/2017 15:00:00 temp的值是: 05/22/2017 15:00:00

I also tried "MM/dd/yyyy" but that also fails. 我也尝试过“ MM / dd / yyyy”,但是也失败了。

In your example, where temp = 05/22/2017 15:00:00, you need your 'format' in ParseExact to match that syntax. 在您的示例中,其中temp = 05/22/2017 15:00:00,您需要ParseExact中的“格式”以匹配该语法。

So I would try this, DateTime test = DateTime.ParseExact(temp, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariateCulture); 所以我会尝试一下, DateTime test = DateTime.ParseExact(temp, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariateCulture);

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

相关问题 在asp.net中无法将字符串识别为有效的DateTime - String was not recognized as a valid DateTime in asp.net “在Asp.net中,字符串未被识别为有效的DateTime - "String was not recognized as a valid DateTime in Asp.net 字符串未被识别为有效的日期时间,asp.net - String was not recognized as a valid DateTime, asp.net ASP.NET控制器FormatException:字符串未被识别为有效的DateTime - ASP.NET Controller FormatException: String was not recognized as a valid DateTime 在asp.net中,不能将字符串识别为有效的DateTime,托管在godaddy上 - String was not recognized as a valid DateTime in asp.net, hosted on godaddy 发布后出错:字符串未被识别为有效的日期时间 asp.net - Error after publishing : String was not recognized as a valid DateTime asp.net 字符串未被识别为有效日期时间asp.net C# - string was not recognized as a valid datetime asp.net c# Javascript日期到ASP.NET日期:字符串未被识别为有效的DateTime - Javascript date to ASP.NET date: String was not recognized as a valid DateTime 在 asp.net 核心 3 中,字符串未被识别为有效的 DateTime - String was not recognized as a valid DateTime in asp.net core 3 字符串不能识别为日期时间格式asp.net? - String is not recognized as datetime format asp.net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM