How do I get the current date if I change the system date to the past

I want the current date if the system date is in the past. Because if iam changes the system date behind my dumper is also changed to the previous date, but I don't want to change the datepixer to my system date. My datepicker should work with the current date not on the system date AND my datepicker should not include for the last days

This is my date picker code:

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');
                });

      

And this is my controller code:

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
            }
        }

      

+3


source to share


2 answers


You can create an ApiController with a method that gets the server date and then using ajax request you get your data in javascript. You have an example:

public class YourApiController : ApiController
{
    [HttpGet]
    [Route("api/getDateFromServer")]
    public DateTime GetDateFromServer()
    {
        return DateTime.Now;
    }
}

      



Then in your javascript you add the following:

$.ajax({
    type: 'GET',
    context: this, 
    url: '/api/getDateFromServer',
}).done(function (data) {
   //here you have date from server
   serverDate = data;
});

      

+1


source


The only option you use besides the system one is to use the online API. There are several free ones you can choose from. Maybe this will help.



+2


source







All Articles