如果系统日期过去,我需要当前日期。因为如果iam更改系统日期超过我的datepicker也会更改为过去的日期但我不想将datepicker更改为我的系统日期。我的datepicker应该在当前日期工作不在系统日期和我的日期选择器不应启用过去日期
这是我的日期选择器代码:
var usTimeZoneVal = new Date().toLocaleString('en-US', { timeZone: 'America/New_York' });
$("#USdate").val(indianTimeZoneVal);
$('#datetimepicker2 , #datetimepicker3')
.datepicker({
autoclose: true,
todayHighlight: true,
format: 'yyyy/mm/dd',
//startDate: '+0d'
startDate: usTimeZoneVal
})
.on('changeDate', function (e) {
$('#datetimepicker2').datepicker('hide');
$('#GuestSearchForm').bootstrapValidator('revalidateField', 'Servicedate');
});
这是我的控制器代码:
public ActionResult GetServiceProviders(RankedServices.Entities.Admin.Services Services)
{
// if (Services != null && Services.SelectedServiceIds != null)
string ServiceDate = Services.Servicedate.ToString("MM/dd/yyyy");/*Start Added by Arun 13-April-2017*/
DateTime USDates = Convert.ToDateTime(Services.USdate);
string USDate = USDates.ToString("MM/dd/yyyy");
int FutureDate = DateTime.Compare(Convert.ToDateTime(ServiceDate), Convert.ToDateTime(USDate));/* End*/
if (Services != null && (Services.SelectedServiceIds != null || Services.ServiceIds != null) && FutureDate >= 0)
{
if (Services.SelectedServiceIds != null)
Services.ServiceIds = string.Join(",", Services.SelectedServiceIds);
// Services.ServiceIds = string.Join(",", Services.SelectedServiceIds);zz
if (Services.ServiceIds != "" && (Services.SubLocationID != "" || Services.Servicedate.Date != null))
{
string UserID = "";
if (Session["UserID"] != null)
{
UserID = Session["UserID"].ToString();
}
Services.lstServiceProviders = ServiceDetails.GetServiceProviders(Services.SubLocationID, Services.ServiceIds.TrimEnd(','), UserID, ServiceDate, Services.Daymode, Services.ProviderID);
IEnumerable<RankedServices.Entities.Admin.Services> lstServices = ServiceDetails.GetServicesList(Services.SubLocationID.ToString());
ViewBag.SelectedServices = new MultiSelectList(lstServices, Services.SelectedServiceIds);
return View("ServicesList", Services);
// return Json(lst, JsonRequestBehavior.AllowGet);
}
else
{
return RedirectToAction("guestsearch", "Home");
}
}
else
{
return RedirectToAction("guestsearch", "Home"); // if none are selected re-direct to Guest-Search
}
}
答案 0 :(得分:2)
除了系统时间之外,您唯一的选择是使用在线时间API。您可以选择一些免费的。也许this会有所帮助。
答案 1 :(得分:1)
你可以创建一个ApiController,使用一个获取服务器日期的方法,然后使用ajax请求你可以在javascript中获取你的数据。你有一个例子:
public class YourApiController : ApiController
{
[HttpGet]
[Route("api/getDateFromServer")]
public DateTime GetDateFromServer()
{
return DateTime.Now;
}
}
然后,在您的javascript中添加以下内容:
$.ajax({
type: 'GET',
context: this,
url: '/api/getDateFromServer',
}).done(function (data) {
//here you have date from server
serverDate = data;
});