简体   繁体   English

如何将asp.net mvc DatePicker的初始值从“ 06/22/2019 00:00:00”格式更改为波斯格式,如1398/04/01

[英]How change the initial value of an asp.net mvc DatePicker from format of “06/22/2019 00:00:00” to Persian format like 1398/04/01

I started an asp.net mvc project and I have below html helper in my view : 我启动了一个asp.net mvc项目,并且在我的视野中有下面的html helper:

@Html.Editor("From_Date"})

and I made this tag to work as Persian DatePicker with below jquery code : 我用下面的jQuery代码使这个标签可以用作波斯DatePicker:

    <link href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.common.min.css" rel="stylesheet">
    <link href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.default.min.css" rel="stylesheet">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="/Content/js/kendo.all.min.js"></script>
<script>
        $(document).ready(function () {

            // create DatePicker from input HTML element
            $("#From_Date").kendoDatePicker();
        });
</script>

This html helper takes an initial value in format of "06/22/2019 00:00:00". 该html帮助器采用格式为“ 06/22/2019 00:00:00”的初始值。 It is too hard and too long to explain how it gets this initial value. 很难解释它如何获得此初始值。 I wanna write a code with jquery to make this HTML helper to show this initial value to Persian format like 1398/04/01 when the document is ready(when the page is loaded) 我想用jquery编写一个代码,以使该HTML帮助程序在文档准备就绪时(加载页面时)将此初始值显示为波斯格式,如1398/04/01。

You can use kendo date picker property like below to set the format you need - 您可以使用下面的kendo日期选择器属性来设置所需的格式-

$("#From_Date").kendoDatePicker({
    format: "yyyy/MM/dd",
    parseFormats: ["dd/MM/yyyy"] });

You can use PersianCalendar from System.Globalization to convert the Gregorian date into a Persian date. 您可以使用PersianCalendarSystem.Globalization的公历日期转换为波斯日期。

You can put the below code straight into your view. 您可以将以下代码直接放入视图中。

@{
    var date = DateTime.Now;  // or from your model (Model.From_Date)
    var pc = new System.Globalization.PersianCalendar();
    var persianDay = pc.GetDayOfMonth(date);
    var persianMonth = pc.GetMonth(date);
    var persianYear = pc.GetYear(date);

    // create the date string  for use in the date picker
    string persianDateString = string.Format("{0}/{1}/{2}", persianYear, persianMonth, persianDay);
 }

$(document).ready(function () {
    $("#From_Date").kendoDatePicker({ format: "yyyy/MM/dd" });
    var datepicker = $("#From_Date").data("kendoDatePicker");
    datepicker.value('@persianDateString');
});

暂无
暂无

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

相关问题 如何在数据表中从 '2021-01-09T00:00:00' LIKE 2021-01-09 转换日期时间格式 - how to convert datetime format from '2021-01-09T00:00:00' LIKE 2021-01-09 in datatable 如何按日期从“yyyy-mm-ddT00:00:00”等格式订购商品 - angular how to order item by date from format like “yyyy-mm-ddT00:00:00” 角度:如何将时间从00:00:01转换为8分49秒格式? - Angular: how to convert time from 00:00:01 to 8 min 49 second format? 是否可以将 fullcalendar 的布局从 00:00:00 - 23:59:00 更改为 19:00:00 - 06:59:00? - It is possible to change the layout of fullcalendar from 00:00:00 - 23:59:00 to 19:00:00 - 06:59:00? 获取格式为2016-01-01T00:00:00.000-00:00的日期 - Get date in format 2016-01-01T00:00:00.000-00:00 将这样的日期格式转换为 2020 年 4 月 20 日星期五 00:00:00 GMT+0530(印度标准时间)到 Javascript 中的 2020-04-20T00:00:00.000Z - convert Date format like this Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time) to 2020-04-20T00:00:00.000Z in Javascript 如何将 9:34, 18:00 之类的字符串格式化为 00:00 - how can I format string like 9:34, 18:00 to format of 00:00 将日期从javascript传递到json http post方法的格式已更改为0001-01-01T00:00:00 - Passing date from javascript to json http post method format changed to 0001-01-01T00:00:00 如何获得 JavaScript 中的字符串总和? (时间格式:00:00:00) - How to get sum of strings in JavaScript? (time format: 00:00:00) 使用Javascript的秒表/倒计时(00:00:00)格式 - Stopwatch/countdown (00:00:00) format with Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM