c# - Insert DateTime format in combobox -


i've harvest_base class datetime formats shown;

class harvest_base {      public static datetime storetime(string date)     {          datetime returnvalue = new datetime();          if (date == "")             return returnvalue;              //time or date component not exist             string[] formats= {"m/d/yyyy h:mm:ss tt", "m/d/yyyy h:mm tt",                 "mm/dd/yyyy hh:mm:ss", "m/d/yyyy h:mm:ss",                 "m/d/yyyy hh:mm tt", "m/d/yyyy hh tt", "m/d/yyyy h:mm", "m/d/yyyy h:mm",                 "mm/dd/yyyy hh:mm", "m/dd/yyyy hh:mm",                 "h:mm tt","hh:mm tt","hh:mm:ss","h:mm","hh:mm","h:mmtt"};             datetime result;              if (datetime.tryparseexact(date, formats, system.globalization.cultureinfo.invariantculture, datetimestyles.none, out result))                 returnvalue = result;             else                 returnvalue = datetime.today;          return returnvalue;      }  } 

i have view class in i've 2 comboboxes starttime , stoptime. want bu these comboboxes should show me values in "hh:mm tt" format.

my questions are:

  1. is binding required here? if yes, please explain code in answer.

  2. if binding not required can achieve result?

either bind combo box directly datetime , apply stringformat on binding, or bind string representing datetime in proper format. use value converter, it's bit overkill.

here's stringformat in binding clause

{binding path=pathtothedatetime, stringformat={}{0:mm-dd-yyyy}} 

change mm-dd-yyyy part liking.


Comments