0

I'm using an api that provides time as a string, for example "14:45". Ultimately, I would like to convert that UTC time string to the user's local time zone, but I'm not exactly sure how to do this.

The only solution I could think of is to convert the string to a DateTime and then convert that DateTime to local before pushing that out as a string back in the original format (ex. "14:45" becomes "11:45"). I'm stuck trying to convert the string to a DateTime given that it's not in the typical format. Any suggestions? Thanks!

robbiestells
  • 265
  • 2
  • 18

1 Answers1

0

Alright I was able to figure it out using the following:

string time = "08:00";
var convertedTime = Convert.ToDateTime(time).ToLocalTime().TimeOfDay.ToString().Substring(0,5);
robbiestells
  • 265
  • 2
  • 18
  • You better understand the logistics of your application but saving only GMT time can be erroneous. You might want to save date and time both for all future purposes when you have to reuse it. – RBT May 14 '16 at 20:50