Well, I am trying to get the default date format of a culture.
For example en-us has "m/dd/yyyy" , en-uk 'd/mm/yyyy'. Culture could be anything at the client machine. and Dateformat can also be anything. like for Culture is en-us but dateformat is dd-MMM-yyyy.
so this case I want to get the ShortDateformatString as m/dd/yyyy not dd-MMM-yyyy.
I tried do this for all the culture by using:
string _cultureInfo = CultureInfo.CurrentCulture.IetfLanguageTag;
CultureInfo shortDatefomatString = new CultureInfo(_cultureInfo);
string old = shortDatefomatString.DateTimeFormat.ShortDatePattern;
but it always returns mt the dd-MMM-yyyy
. i need the default one not the set on the machine.
I believe the issue is the way you're retrieving the desired culture.
This should give you the default culture settings:
var cultureLanguageTag = CultureInfo.CurrentCulture.IetfLanguageTag;
var defaultCulture = CultureInfo.GetCultureInfoByIetfLanguageTag( cultureLanguageTag );
Constructing one with a string is supposed to be used with the culture name, I don't know if it should work with the IETF tag, it may have just been returning the current culture in that case.
According to MSDN, CurrentCulture
will return the culture in one of the following ways:
CultureInfo.DefaultThreadCurrentCulture
if it is not null. (Note that unless you specifically set a culture, this will always be null.)GetUserDefaultLocaleName
function. This will return whatever Culture you set in Control Panel.It may be possible that if you change the culture in Control Panel, you will not see the changes until you restart your computer.
To test whether cultures are showing the correct dates, you can manually choose a culture instead of using the system culture by using CultureInfo.CreateSpecificCulture("en-US");
(replacing "en-US" with the culture codes of other countries).
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