c# - datetime format : can a computer be forced to use a particular format? -


i have developed winform application makes use of format dd-mm-yyyy hh:mm:ss (24 hr system).

when try application on computer, error, because standard datetime format there dd/mm/yyyy hh:mm:ss am/pm.

moreover, controls in datetime stored, hold datetime string in different format: d/m/yyyy hh:mm:ss am/pm, eg 1/4/2013 12:00:00 a.m. instead of 01/04/2013 12:00:00 a.m.

can force other system somehow use same format? novice here. help.

when displaying datetime object, there 2 things keep in mind.

  • culture settings: when don't specify explicit culture, culture that's set system application running on used.
  • format strings: when converting datetime object string, can give format string argument specifies how datetime object should formatted. like: "d" short date pattern or "t" display time.

combining these 2 give full control on how display datetime objects. should careful in forcing culture setting on user. if application should support globalization (so multiple users different cultures can use app) shouldn't depend on specific culture. instead, should store data culture-insensitive , format users culture when display on screen.

here example how use both cultureinfo object , format string:

string mydate = "10-05-2013 08:52:30"; datetime date = datetime.parse(mydate);  console.writeline(date.tostring("d", new cultureinfo("en-us"))); // 5/10/2013 console.writeline(date.tostring("d", new cultureinfo("nl-nl"))); // 10-5-2013  console.writeline(date.tostring("f", new cultureinfo("nl-nl"))); // vrijdag 10 mei 2013 08:52 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -