I have an account in int, that I need to return it for hours, and it is working perfectly, the error occurs when the time appears 24, and it should appear 00:00. Here's how I'm doing:
string horaStg;
decimal valor = int.Parse(item.HoraInicio);
valor = (valor / 60);
var inicio = valor.ToString().Split(char.Parse(","));
string hora = inicio[0];
try
{
string minuto = "0," + inicio[1];
string m = Math.Round(decimal.Parse(minuto.ToString()) * 60).ToString();
horaStg = DateTime.Parse(hora + ":" + m.Substring(0, 2)).ToString("HH:mm");
}
catch
{
horaStg = DateTime.Parse(hora + ":" + "00").ToString("HH:mm");
}
How can I convert to 00:00? Because of the way it is when it is midnight, it appears 24 and returns me the following error:
The DateTime represented by the string is not supported in System.Globalization.GregorianCalendar.
I made an if, like this:
if (hora == "24")
{
hora = "00";
}
But do not you have some direct conversion?