Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get custom datetime format from standard format

In my script, I receive a standard format like "D", "f", "R" or others. This is a Standard DateTime Format, according to MSDN.

Taking into account the current culture of the user, I would like to get the custom format of this standard format.

Example, let's say my user is from France (fr-FR) :

"d" = "dd/MM/yyyy"

"D" = "dddd d MMMM yyyy"

"F" = "dddd d MMMM yyyy HH:mm:ss"

like image 943
NLemay Avatar asked Dec 07 '22 06:12

NLemay


1 Answers

You need a char version of that format, but then you could do it like this:

CultureInfo culture = //get your culture
var patterns = culture.DateTimeFormat.GetAllDateTimePatterns(yourFormatChar);
like image 55
It'sNotALie. Avatar answered Dec 09 '22 14:12

It'sNotALie.