I have .net core 5.0 application and try to get DateTime from appsettings.json
appsettings.json:
"TimeModel": {
"RestartDuration": "27.10.2021 12:30:00"
}
Code:
services.Configure<TimeModel>(
configuration.GetSection("TimeModel"));
Error:
System.InvalidOperationException: Failed to convert configuration value at 'TimeModel:RestartDuration' to type 'System.DateTime'.
---> System.FormatException: 27.10.2021 12:30:00 is not a valid value for DateTime.
---> System.FormatException: String '27.10.2021 12:30:00' was not recognized as a valid DateTime.
"27.10.2021T12:30:00"
– Guilbert"2021-10-27T12:30:00"
worked. OrParseExact
: dotnetfiddle.net/do45ki – Radiation