asp.net - Getting valid Datetime such as Month/day/year format -
my string "21.05.2013 00:00:00"
but want : "05/21/2013"; used format
string.format("{0:m d yy}", myobject.startat.tostring());
but instead of "05/21/2013" produce "05.21.2013 00:00:00"
edited area ----------
i tried below code still give wrong format still give "05.20.2013" instead of "05/20/2013";
datetime arrivaldate = datetime.parseexact(hotelsearchmodel.startat.tostring(), "dd.mm.yyyy hh:mm:ss", cultureinfo.invariantculture); datetime departuredate = datetime.parseexact(hotelsearchmodel.startat.tostring(), "dd.mm.yyyy hh:mm:ss", cultureinfo.invariantculture); request.arrivaldate = arrivaldate.tostring("mm/dd/yyyy"); request.departuredate = departuredate.tostring("mm/dd/yyyy");
is startat
string or datetime? if it's string, you'll need convert datetime formatting work. also, you'll need change formatting pattern mm/dd/yyyy 05/21/2013:
datetime dt = datetime.parseexact(myobject.startat, "dd.mm.yyyy hh:mm:ss", cultureinfo.invariantculture); string s = dt.tostring("mm/dd/yyyy");
Comments
Post a Comment