c# - DateTime is not in proper format -


i have property follows:

[datatype(datatype.datetime)] [displayformat(applyformatineditmode = true, dataformatstring = "{0:dd/mm/yyyy}")] public datetime ? enddate { set; get; } 

when use

@html.displayfor(modelitem => item.enddate) 

i result follows:

17.07.2013  

why happening?

there's several ways this.

either:

  • change regional settings user running web application
  • use correct cultureinfo object when formatting
  • set default cultureinfo object on current thread
  • escape slashes

to provide cultureinfo object when formatting:

@html.displayfor(modelitem => item.enddate.tostring("dd/mm/yyyy", cultureinfo.getculture("en-us"))) 

to set default cultureinfo object:

thread.currentthread.currentculture = cultureinfo.getculture("en-us"); 

to escape slashes, use single quotes:

[displayformat(applyformatineditmode = true, dataformatstring = "{0:dd'/'mm'/'yyyy}")] 

note code ends in datetime.tostring(string) or 1 of overloads, that's place clues this.


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 -