I need to be able to get the current date as string in different formats.
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var utcNow = DateTime.UtcNow;
var localTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, timeZone);
Console.WriteLine(localTime.ToShortDateString());
The example above prints the date as 22-01-2018
, which is the danish format. But I need it to print the date as 1/22/2018
(example only).
I know that I can format dates using ToString
, but I need to be able to format the date from a range of different timezones (the user picks the timezone).
Can I somehow tell ToShortDateString
to use another culture and if so, how do I get from TimeZoneInfo
to CultureInfo
?