DateTime format according to the culture in MVC

前端 未结 1 1354
感动是毒
感动是毒 2021-01-26 01:19

I have an MVC view where I list a dateTime type column named \"CreatedOn\", the values are formatted like this: \'DD/MM/YYYY HH:MM:SS\', When I click on edit l

相关标签:
1条回答
  • 2021-01-26 02:07

    jQuery Validate doesn't understand cultures.

    I believe for dates, it just calls the javascript: new Date(value).

    You can fix this with a globalization plugin and a bit of javascript.

    Microsoft wrote a globalization plugin here: https://github.com/jquery/globalize

    Then you want to replace the validation method with something like this:

    $.validator.methods.date = function (value, element) {
      return this.optional(element) || Globalize.parseDate(value);
    }
    

    You probably also want to replace the other methods for numbers etc. - have a look at the bottom of jquery.validate.js for examples.

    0 讨论(0)
提交回复
热议问题