Right now I'm doing:
bool UseMetricByDefault() {
return TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalHours >= 0;
}
This works for distinguishing USA from Europe and Asia, but it ignores South America.
Is there a better way?
Use the RegionInfo
class in the System.Globalization
namespace:
bool isMetric = RegionInfo.CurrentRegion.IsMetric;
If you want a specific region, you can use one of the following:
// from a CultureInfo
CultureInfo culture = ...;
RegionInfo r = new RegionInfo(culture.Name);
// from a string
RegionInfo r = new RegionInfo("us");
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