asp.net - How to use culture for changing the datetime format -


i want change date format

cultureinfo ci = new cultureinfo("en-us");  thread.currentthread.currentculture = ci;  string fromdate =(txtfrom.text);  string todate = (txtto.text);  datetime dt =datetime.parse(fromdate);  datetime d =datetime.parse(todate);  _divapath.from_date = convert.todatetime("d",ci);  _divapath.to_date = convert.todatetime("d",ci); 

but show exception given datetime not correct format.how change datetime function...

please explain

first, don't need change culture if want parse or convert dates given cultureinfo, unnecessary:

thread.currentthread.currentculture = ci; 

you can use datetime.parse overload accepts culture:

datetime dt = datetime.parse(fromdate, ci);  

the exception raised @ convert.todatetime("d",ci); since d not valid date ;)

maybe from_date string property , want convert datetime short-date-string, either use:

_divapath.from_date = dt.tostring("d", ci); 

or

_divapath.from_date = dt.toshortdatestring(); // uses current-culture 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -