So I'm using an API where a datetime is retrieved in the following format DIE, 28. AUG 2018 12:38:38
The closest datetime format I found was this ddd, dd. MMM yyyy HH:mm:ss
.
It works only if its DI
, but the API provides this day as DIE
.
Does a format exist that can parse DIE, 28. AUG 2018 12:38:38
I believe that the developers of this API use some different format.
Does anyone know what it could be ?
EDIT: some code I tried
static void Main(string[] args)
{
const string DateTimeFormat = "ddd, dd. MMM yyyy HH:mm:ss";
var deCultureInfo = new CultureInfo("de-DE");
string input = "DIE, 28. AUG 2018 14:12:01";
// both throws exception
var timestamp1 = DateTime.ParseExact(input, DateTimeFormat, deCultureInfo);
var timestamp2 = DateTime.Parse(input, deCultureInfo);
//Console.WriteLine(DateTime.Now.ToString(deCultureInfo));
}
You can override ddd
in the property AbbreviatedDayNames
of the used DateTimeFormatInfo
:
const string DateTimeFormat = "ddd, dd. MMM yyyy HH:mm:ss";
var deCultureInfo = new CultureInfo("de-DE");
var input = "DIE, 28. AUG 2018 14:12:01";
CultureInfo ci = CultureInfo.CreateSpecificCulture("de-DE");
DateTimeFormatInfo dtfi = ci.DateTimeFormat;
// addjust this to your german strings
dtfi.AbbreviatedDayNames = new[] { "SON", "MON", "DIE", "MIT", "DON", "FRE", "SAM" };
var timestamp1 = DateTime.ParseExact(input, DateTimeFormat, dtfi);
See this from the doku.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With