如何将kendo日期选择器日期解析为MMMyyyy字符串格式?

时间:2020-05-10 00:11:55

标签: asp.net asp.net-mvc kendo-ui kendo-grid

我使用Kendo Date Picker来计算会计月份,该字段是文本字段,我想使用DatePicker来选择月份和年份,并显示为'052020'作为文本

但是当我选择数据时,它将日期显示为Tue Jun 09 2020 00:00:00 GMT-0700 (Pacific Daylight Time),我如何获得一个月和一个日期。

在我的网格中,我有这个

 new GridColumnSettings
        {
            Member = nameof(Sales.AcountingMonth),
            MemberType = typeof(string),
            Title = "Acounting Month",          
        },

并在我的弹出窗口中

 @(Html.Kendo().DatePicker()
            .Name(nameof(Sales.AcountingMonth))          
            .Format("MMMyyyy")
            .Value(nameof(Sales.AcountingMonth))           
            )

1 个答案:

答案 0 :(得分:0)

据我了解,您需要一种从c#MMYYYY对象中获取DateTime格式的字符串的方法。好吧,您可以执行此操作,如果您通过DateTime.ToString()方法,则可以以所需的格式提供给它,它将产生结果字符串。在您的情况下,将是这样的:

@(
    Html.Kendo()
        .DatePicker()
        .Name(nameof(Sales.AcountingMonth))          
        .Format("MMMyyyy")
        .Value(Sales.AcountingMonth.ToString("MMMyyyy")) 
        // I assume AccountingMonth is of type DateTime.
        // Notice, I removed the nameof call that you were making,
        // which eventually was returning the name of the property that you were referencing.
)

PS:我只记得我回答了一个类似的问题,几天前“ YOU”问了这个问题,与这个问题非常相似。选中this answer.