DateTime (date and hour) validation with Data Annotation

前端 未结 4 2177
醉话见心
醉话见心 2020-11-29 10:03

I have the following code:

        [DisplayName(\"58.Date and hour of birth\")]
        [DataType(DataType.DateTime, ErrorMessage = \"Please enter a valid da         


        
4条回答
  •  情歌与酒
    2020-11-29 10:54

    If you just pass date in a string it will consider it as 12:00 AM. If you want to pass time within a string use "06/06/2011 7:00 PM" syntax.

    Other workaround would be to keep your string as is, convert it to DateTime & then AddHours &/or AddMinutes to DateTime object depending on your needs.

提交回复
热议问题