Format Date based on User's Locale in a UWP App

2016, Jan 17    

Another app I was working on recently needed to fetch the current date but also be in the correct format depending on the location settings found in Settings -> Time & Language -> Region & Language -> Country or region in Windows 10.

The following code did exactly what I wanted

using Windows.Globalization;
using Windows.Globalization.DateTimeFormatting;

and then

GeographicRegion region = new GeographicRegion();
string code = region.CodeTwoLetter;
var formatter = new DateTimeFormatter("year month day", new[] { code });
DateTime dateFormat = new DateTime(year, month, day);
var formattedDate = formatter.Format(dateFormat);

Pretty simple, but took me a few minutes to work out