set specific timezone for jquery datetime picker

Discussion in 'Programming/Scripts' started by Maede, Nov 4, 2019.

  1. Maede

    Maede New Member

    Hi,
    I use jquery datetime picker V1.3.5. how can I set specific time zone?
    sorry I am not good in jquery.

    I'll really appreciate any help.
    Thanks in advance.
     
  2. Harsh Shah

    Harsh Shah Banned

    Hi @Maede
    You can set timezone manually by storing specific timezone value to the variable and then add that variable to the date-picker plugin.
    Consider below code:
    HTML:
    Select Date: <input type="text" id="myDate" /> <br />
    Here i set id to the input text.
    Now we need to write jquery code like below:
    Code:
    $(document).ready(function () {
    $('#myDate').datepicker({
    });
    var a = new Date();
    var timeZoneOffset = +5*60 //Set specific timezone according to our need. i.e. GMT+5
    a.setMinutes(d.getMinutes() + a.getTimezoneOffset() + timeZoneOffset );
    $("#myDate").datepicker("option","maxDate", a );
    });
    Let me explain you above code.
    Here i used Jquery Datepicker UI plugin and added this to the input field which id has #myDate.
    Note: you need to add Jquery CDN to your html page's head section to use datepicker UI plugin.
    You can get CDN from here: https://jqueryui.com/datepicker/

    Now further to the code, i have stored GMT + 5 timezone to the variable manually then set that variable to the date picker. maxDate option allows defining maximum possible date selection after that dates are not selectable in the datepicker.

    Try above code by adding to your code. and let me know if you have any query.
    Hope This will help you.
    Thank you.
     
    Last edited: Nov 5, 2019
  3. Maede

    Maede New Member

    Hi Harsh
    It works fine.
    Also I find following code :

    d = new Date(new Date().toLocaleString("en-UK",{timeZone:'Europe/London'}));

    I added it to "jquery.datetimepicker.js" and it works correctly too.

    Thanks a lot. :)
     
    Shubham Gupta likes this.
  4. Shubham Gupta

    Shubham Gupta New Member

    The last comment solution worked like a charm
     

Share This Page