12 to 24
private string ConvertTo24HourFormat(string strTime) //HH:MM AM/PM
{
string FinalTime=string.Empty;
if (!string.IsNullOrEmpty(strTime))
{
try
{
string[] InTime = strTime.Split(':');
int h = Convert.ToInt32(InTime[0].ToString());
string[] AMPM = InTime[1].Split(' ');
if (AMPM[1].ToString() == "PM")
{
h += 12;
}
if (AMPM[1].ToString() == "AM" && h.ToString()=="12")
{
h = 00;
}
FinalTime = h + ":" + InTime[1];
//if(h>
}
catch (Exception) { }
}
return FinalTime;
}
24 to 12
private string ConvertTo12HourFormat(string strTime) //HH:MM AM/PM
{
string FinalTime = string.Empty;
if (!string.IsNullOrEmpty(strTime))
{
try
{
string[] InTime = strTime.Split(':');
int h = Convert.ToInt32(InTime[0].ToString());
string[] AMPM = InTime[1].Split(' ');
if (AMPM[1].ToString() == "PM")
{
h -= 12;
}
if (AMPM[1].ToString() == "AM" && h.ToString() == "00")
{
h = 12;
}
FinalTime = h + ":" + InTime[1];
//if(h>
}
catch (Exception) { }
}
return FinalTime;
}