c# time format weirdness -
i have following string thetimeformat custom time format:
"{0:h:mm tt}"
i have following datetime thetime:
{1/14/2011 2:19:00 am}
i have following statement
thistime = thetime.tostring(thetimeformat);
why thistime equal "{0:2:19 am}
" . should 2:19 , i'm not seeing why. not in gridview, use following statement , works charm:
((boundfield)(mygrid.columns[0])).dataformatstring = theuserpreferences.usertimeformat
; theuserpreferences.usertimeformat same format string.
any suggestions?
when put time format datetime
's tostring
method, don't need placeholder; is, have this:
thetimeformat = "h:mm tt";
and
thistime = thetime.tostring(thetimeformat)
would give desired output.
edit:
per extended question in comment, allow put format in requires placeholder (and store aforementioned version of thetimeformat in db):
string formatwithplaceholder = "{0:" + thetimeformat + "}";
i briefly played around string.format
instead of concatentation, having braces in format giving issues. nonetheless, works, don't particularly concatenation.
Comments
Post a Comment