DateTime.ParseExact() does not grok 24-hour time values?
“hh” is the 12-hour clock format (01 to 12). You need to use “HH” for a 24 hour clock. DateTime dt = DateTime.ParseExact(time, “HH:mm”, CultureInfo.InvariantCulture);
“hh” is the 12-hour clock format (01 to 12). You need to use “HH” for a 24 hour clock. DateTime dt = DateTime.ParseExact(time, “HH:mm”, CultureInfo.InvariantCulture);
The System.Convert class has a static ToString overload that takes an object. Convert.ToString(obj, CultureInfo.InvariantCulture); Based on my benchmarks, this is roughly twice as fast as string.Format(CultureInfo.InvariantCulture, “{0}”, value) and, more importantly, it looks cleaner. However, if you are building a string already, I’d recommend FormattableString.Invariant. FormattableString.Invariant($”Object value: {obj}”)
You can use the second argument to the toString function and use any language/culture you need… You can use the “d” format instead of ToShortDateString according to MSDN… So basically something like this to return as Australian English: CultureInfo enAU = new CultureInfo(“en-AU”); dt.ToString(“d”, enAU); you could modify your method to include the language and … Read more
You can programatically list the cultures available in your application // Pass the class name of your resources as a parameter e.g. MyResources for MyResources.resx ResourceManager rm = new ResourceManager(typeof(MyResources)); CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo culture in cultures) { try { ResourceSet rs = rm.GetResourceSet(culture, true, false); // or ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture.TwoLetterISOLanguageName), … Read more
I think you will need to add the following. Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-IN”); Thread.CurrentThread.CurrentUICulture = new CultureInfo(“en-IN”); FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata( XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); Read more here: http://www.west-wind.com/weblog/posts/2009/Jun/14/WPF-Bindings-and-CurrentCulture-Formatting Just to give you an example, this is how I initialize the Culture in my program, based on the user setting, but you can simply replace UserSettings.DefaultCulture and UserSettings.Default.UICultrue with … Read more
The factory method has an fallback when it fails to create the culture info. So if you use a specific culture like ‘en-XX’, the culture info instance can’t be created, an exception will throw and a retry with the neutral culture ‘en’ will succeed. Below the source of the factory method public static CultureInfo CreateSpecificCulture(string … Read more
I think this should work: double.Parse(currencyValue, NumberStyles.AllowCurrencySymbol | NumberStyles.Currency); Here you can see more about the NumberStyles. Edit: In case anyone sees this answer without looking at the other answers/comments, this answer answered the question as written, but storing currency as a double is not a good idea, and it would be better to use … Read more
Use the Currency standard format string along with the string.Format method that takes a format provider: string.Format(new System.Globalization.CultureInfo(“en-GB”), “{0:C}”, amount) The CultureInfo can act as a format provider and will also get you the correct currency symbol for the culture. Your example would then read (spaced for readability): <td style=”text-align:center”> <%# string.Format(new System.Globalization.CultureInfo(“en-GB”), “{0:C}”, Convert.ToSingle(Eval(“tourOurPrice”)) … Read more
Simply Use the code below : private string changePersianNumbersToEnglish(string input) { string[] persian = new string[10] { “۰”, “۱”, “۲”, “۳”, “۴”, “۵”, “۶”, “۷”, “۸”, “۹” }; for (int j=0; j<persian.Length; j++) input = input.Replace(persian[j], j.ToString()); return input; }
In fact CultureInfo.InvariantCulture can be used here. The parameter expects IFormatProvider, an interface that CultureInfo implements. But InvariantCulture is invariant in the sense that it does not vary with the user’s settings. In fact, there is no culture that accepts either , or . as decimal separator – they are all one or the other. … Read more