c# - How to convert DateTime variable to represent date in a particular format? -


this question has answer here:

i have string variable represents date:

string arrival = "03-05-2013 00:00:00";//format dd-mm-yyyy hh:mm:ss 

i need convert datetime variable holding date in exact same format(dd-mm-yyyy hh:mm:ss). so, tried parsing string variable:

datetime arr = datetime.parseexact(arrival,"dd-mm-yyyy hh:mm:ss",cultureinfo.invariantculture); 

however, turns out variable arr holds datetime value has formatting different (it held value "3/5/2013 12:00:00 am"). idea appreciated.

arr not "have" formatting because datetime value, not string. when try display gets displayed result of datetime.tostring(), the documentation says same datetime.tostring("g") (and in turn affected executing thread's current culture).

if want display in particular format, use arr.tostring("format specification") -- see docs.


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 -