简体   繁体   English

在日期时间选择器中更改格式日期

[英]changing format date in datetime picker

In mvc4 application I used datetime format dd.MM.YYYY HH:mm 在mvc4应用程序中,我使用日期时间格式dd.MM.YYYY HH:mm

EditorTemplates > DateTime.cshtml EditorTemplates> DateTime.cshtml

@Html.TextBoxFor(model => model, "{0:dd.MM.yyyy HH:mm}", ViewData["htmlAttributes"])

and I parsed it like this 我这样解析

DateTime.ParseExact(myDate, "dd.MM.yyyy", CultureInfo.InvariantCulture);

where myDate is passed as parameter ofcourse. 其中myDate作为课程参数传递。

Inside jquery datetime picker I used code (abbreviated inside function) 在jquery datetime picker内部,我使用了代码(在function内部缩写)

... format('DD.MM.YYYY HH:mm')

how can I change this code to use following datetime format 如何更改此代码以使用以下日期时间格式

 2016-04-04 23:05

I tried with 我尝试过

@Html.TextBoxFor(model => model, "{0:YYYY-MM-DD HH:mm}", ViewData["htmlAttributes"])

and parsing like 并像

DateTime.ParseExact(myDate, "YYYY-MM-DD", CultureInfo.InvariantCulture)

and inside js 和里面的js

... format('YYYY-MM-DD HH:mm')

but I'm getting year as YYYY instead of 2016 . 但我将年份改为YYYY而不是2016

Custom Date and Time Format Strings are case sensitive. 自定义日期和时间格式字符串区分大小写。 There is no YYYY or DD as a specifiers. 没有YYYYDD作为说明符。 That's why those strings will be in as they are when you get it's string representation. 这就是为什么当您获得字符串表示形式时这些字符串将保持原样的原因。

From docs; 来自文档;

Any other character. 任何其他字符。

The character is copied to the result string unchanged. 字符将原样复制到结果字符串。

Your format should be as yyyy-MM-dd . 您的格式应为yyyy-MM-dd

尝试使用"yyyy-MM-dd"而不是"YYYY-MM-DD"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM