xeo zer

xeo zer

  • NA
  • 52
  • 4.8k

how to convert military time to standard

Jun 23 2017 6:59 AM
DateTime ottimein, ottimeout;
DateTime pmtimein, pmtimeout;
DateTime amtimein, amtimeout;
DateTime extra;
amtimein = DateTime.Parse(txt1.Text + "AM");
amtimeout = DateTime.Parse(txt2.Text + "AM");
pmtimein = DateTime.Parse(txt3.Text + "PM");
pmtimeout = DateTime.Parse(txt4.Text + "PM");
ottimein = DateTime.Parse(txt5.Text + "PM");
ottimeout = DateTime.Parse(txt6.Text + "PM");
extra = DateTime.Parse(txtExtra.Text + "AM").AddHours(12);
TimeSpan ts = new TimeSpan(0);
var am = amtimein;
var amout = amtimeout;
TimeSpan diff = amout.Subtract(am);
var pmin = pmtimein;
var pmout = pmtimeout;
TimeSpan diffpm = pmtimeout.Subtract(pmtimein);
var otin = ottimein;
var otout = ottimeout;
TimeSpan diffot = ottimeout.Subtract(ottimein);
if (diff < ts)
{
var res = diff + TimeSpan.FromHours(12);
var res_s= diffpm;
var res_r=diffot;
var _s = res + res_s + res_r;
txtm.Text = res.ToString(@"hh\mm");
}
else
{
var res = diff;
var res_s = diffpm;
var res_r = diffot;
var _s = res + res_s + res_r;
txtm.Text = res.ToString(@"hh\mm");
}

Answers (2)