值xxx对yyy无效。日期时间格式错误 [英] The value xxx is not valid for yyy. Wrong datetime format

查看:167
本文介绍了值xxx对yyy无效。日期时间格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我从一个输入框中获取dateTime,其中datepicker用这段代码初始化:

Hello I'm getting my dateTime from a input box with datepicker initialized with this code:

$(document).ready(function () {
    $("#CreationDate").datepicker({ autoclose: true, todayHighlight: true, language: "pl", format: 'dd/mm/yyyy' });
})

正如你可以看到的格式是 dd / mm / yyyy
这是我的模型:

As You can see format is dd/mm/yyyy This is my model:

public int Id { get; set; }
public int DeviceId { get; set; }
public string SerialNo { get; set; }
public System.DateTime CreationDate { get; set; }

当我尝试将我的模型输入到数据库控制器拒绝时,因为 Model .isValid = false

And when I try to input my model into database controller refuses because Model.isValid=false

如果我将格式更改为 mm / dd / yyyy 是有效的,但这不是选项,因为用户不想输入Us格式的数据。
我放入web.config全球化行:

If I change format to mm/dd/yyyy model is valid but this is no option because users don't want to enter data in Us format. I put in web.config globalization line:

<globalization culture="en-GB"/>

无效
我该如何修改我的代码?
或唯一简单的电话控制器动作?

with no effect how should I modify my code? or the only simpleen call controler action?

推荐答案

问题: code> dd / mm / yyyy 无效。

Problem : Your custom dateformat dd/mm/yyyy is invalid.

mm 用于表示分钟

解决方案:您应该使用资本 MM 代表 Month
所以你的格式应该是 dd / MM / yyyy

Solution : You should use capital MM to represent Month. so your Format should be dd/MM/yyyy

mm 分钟,从 00 通过 59

MM 01 通过 12

mm The minute, from 00 through 59.
MM The month, from 01 through 12.

尝试这样:

$(document).ready(function () {
    $("#CreationDate").datepicker({ autoclose: true, 
    todayHighlight: true, language: "pl", format: 'dd/MM/yyyy' });
})

这篇关于值xxx对yyy无效。日期时间格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆