How do I convert a DateTime from the local timezone returned by DateTime.Now to another timezone than Utc. On desktop we have the TimeZoneInfo.ConvertTimeBySystemTimeZoneId(), but it’s not available on windows phone!
This java snippet shows roughtly what I want to do
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
TimeZone tz = TimeZone.getDefault();
format.setTimeZone(TimeZone.getTimeZone("GMT"));
str = format.format(new Date());
This is not possible to do using the system libraries as there is no way to create
TimeZoneInfoobjects other than local and utc. They have also sealed the class.You can however use this simple library to enable conversion to non-local time zones.
https://nuget.org/packages/WinRTTimeZones
Use it like this:
When the
DateTimeis converted it is an easy exercise to format it as you want. I recommend to format the date in the local format (not the local timezone) to make easy for the user to understand the date.