Home > Software engineering >  get user language date format in current culture
get user language date format in current culture

Time:09-12

By date format I don't mean the one used by .net to format date types

Date format shown to the user with a french culture could be jj/mm/aaaa (jour = day, mois = month, an = year). For example in html an <input type="date" /> would show the format above as an input placeholder.

does .net have this format info available ?

CodePudding user response:

When you specify the culture (replace en-US with your culture:

CultureInfo.GetCultureInfoByIetfLanguageTag("en-US").DateTimeFormat.ShortDatePattern;

Or with the Current Culture

CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

RESULTS The first will return M/d/yyyy The second will return (in my case, as I am in Switzerland) dd/MM/yyyy

CodePudding user response:

Hi you can use CultureInfo

You'll need to import Globalization

using System.Globalization;

If you need more explanation, click here

Here's a code example :

DateTime thisDate = new DateTime(2022,08,13);
CultureInfo culture = new CultureInfo("fr-FR");
Console.WriteLine(thisDate.ToString("d", culture));
  • Related