c# - After formatting Month part of the datetime changes to "00" -
i have datetime object in format
startdate = 19-03-2014 00:00:00 and trying convert 03/19/2014. here code that
<input type="text" value="<%#convert.todatetime(eval("startdate")).tostring("mm/dd/yyyy") %>"/> but returns string
00-19-2014 i can't understand why happens, can 1 point out going wrong here?
mm specifier minutes. prints 00 because minutes of startdate 00.
use mm specifier instead months 01 12.
convert.todatetime(eval("startdate")).tostring("mm/dd/yyyy") for more information, take at;
datetime has no implicit format, datetime value. can format string.
as additional, "/" custom format specifier has special meaning of "replace me current culture's date separator"
looks currentculture's dateseperator - , / replace it.
if want output / seperator, can use culture has / dateseperator (like invariantculture) second parameter in tostring method like;
convert.todatetime(eval("startdate")).tostring("mm/dd/yyyy", cultureinfo.invariantculture) or can escape no matter culture use like;
convert.todatetime(eval("startdate")).tostring(@"mm\/dd\/yyyy")
Comments
Post a Comment