c# - How to convert HttpCookie DateTime? -
i have following code trying check datetime
httpcookie date1 = request.cookies.get("date1"); datetime? adate = date1 != null datetime.parseexact(date1.value, "dd/mm/yyyy", null): (datetime?) null; i tried convert.todatetime(date1) none of them work. got following exception string not recognized valid datetime error
from comments:
when debug see value in format 03%2f31%2f2014
then try:
datetime.parseexact(webutility.urldecode(date1.value), "mm/dd/yyyy", null) note null means parse using current culture. if value always in format, may wish use cultureinfo.invariantculture instead.
or, if indeed mutating value based on current culture, should try this:
datetime.parse(webutility.urldecode(date1.value)) i'm not sure why value url encoded. perhaps should investigate how set cookie begin with. should probably setting using iso8601 format (yyyy-mm-dd) invariant culture.
Comments
Post a Comment