Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a valid German Datetime Culture format?

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));

}
like image 233
gneric Avatar asked Dec 10 '22 05:12

gneric


1 Answers

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.

like image 107
ChristianMurschall Avatar answered Dec 12 '22 17:12

ChristianMurschall