c# - DateTime.Parse, Latvian culture settings -
i sending in string in dd/mm/yyyy
format, being parsed lv-lv
culture set per web.config globalization setting.
i comparing date datetime.now
see if in past.
the problem is, datetime.parse
converts string dd.mm.yyyy
format, datetime.now has mm.dd.yyyy
format, comparison fails.
why datetime.now
different output datetime.parse
, on same thread culture?
thanks!
(update) code using:
inputtext contains input form in dd.mm.yyyy format
datetime date = datetime.parse(inputtext, cultureinfo.currentculture); // check it's not in past this.isvalid = (date.compareto(datetime.now) > 0);
[datetime.now] in context in mm.dd.yyyy format using lv-lv cultureinfo [date] in dd.mm.yyyy format after datetime.parse
a datetime
not have formatting - point in time.
if viewing it, means outputting it. use correct culture output date.
datetime.tostring
has overloads take format provider such cultureinfo
:
string formatted = datetime.tostring(new cultureinfo("lv-lv"));
if not specified (in code or configuration), default system culture used (or cultureinfo.invariantculture
, in cases).
Comments
Post a Comment