Saturday 10 July 2021

Date comparison in Client Side considering Timezone - Javascript/Jquery

I have a requirement there i need to compare the date with local time. I am setting a Date in DatetimePicker which is in EST DateTime. So i need to compare it with current time and if it is less than current time, I need to show validation alert. Current time in user machine will be of different timezones. So I always need to convert current time zone to to EST time zone before comparing. If current Timezone in user machine in EST,then need to consider the same value and conversion is not required.How can I achieve this in Javascript/Jquery.How can I modify below javascript to handle above case.

iam setting START_DATE n cshtml page as follows

  <div class='input-group date' id='datetimepicker1'>
                                @Html.EditorFor(model => model.START_DATE, new { htmlAttributes = new { @class = "form-control z-index-0" } })
                                <span class="input-group-addon" id="calenderStart">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>

In Javascript side...

var startDate= new Date($("#START_DATE").val());
var currentDateTime= new Date();  //Convert to EST if it is in DifferentTimeZone.Doubt on this part
if(startDate < currentDateTime)
{
 alert ("StartDateTime should be greater than current EST DateTime);
}


from Date comparison in Client Side considering Timezone - Javascript/Jquery

No comments:

Post a Comment