[英]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. 您可以使用PersianCalendar从System.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.