How to make the time format from h:m tt to hh:mm tt in c# -


i trying show time(s) in dropdown. managed using code:-

        datetime dttime = new datetime(2015,01,01,00,00,00);          datatable dt = new datatable();         dt.columns.add("time");          (int = 0; < 48; i++)         {             string tm = dttime.toshorttimestring();             datarow dr = dt.newrow();             dr["time"] = tm;             dt.rows.add(dr);              dttime = dttime.addminutes(30);         }          ddltime.datasource = dt;         ddltime.datatextfield = "time";         ddltime.datavaluefield = "time";         ddltime.databind(); 

the output :-

enter image description here

now, want make format hh:mm tt. example, 1:00 should 01:00 am. can me? thanks.

replace

dttime.toshorttimestring(); 

with

dttime.tostring("hh:mm tt"); 

Comments