bootstrap datepicker setDate format dd/mm/yyyy

前端 未结 12 915
轮回少年
轮回少年 2021-02-03 20:14

I have to set the date in my datepicker in dd/mm/yyyy format. Whet I\'m trying to do, with Javascript is this:

  var year = 2014;
  var month = 5;
  var day = 10         


        
相关标签:
12条回答
  • 2021-02-03 20:16

    format : "DD/MM/YYYY" should resolve your issue. If you need more help regarding available formats, please visit http://momentjs.com/ which is used by this control internally.

    I was facing an issue where this "format" thing was working fine on local machine but when I deployed the application on server, the date was not getting populated and the control was empty. when I commented the format code, it started working but then I didn't have the format that I needed. I fixed that issue using globalization entries in web.config.

    <system.web>
        <globalization
        requestEncoding="utf-8"
        responseEncoding="utf-8"
        culture="en-GB"
        uiCulture="en-GB" />    
    </system.web>
    

    This helped in ensuring that both local & server environments have same culture.

    0 讨论(0)
  • 2021-02-03 20:24

    Try this

     format: 'DD/MM/YYYY hh:mm A'
    

    As we all know JS is case-sensitive. So this will display

    10/05/2016 12:00 AM

    In your case is

    format: 'DD/MM/YYYY'
    

    Display : 10/05/2016

    My bootstrap datetimepicker is based on eonasdan bootstrap-datetimepicker

    0 讨论(0)
  • 2021-02-03 20:32

    There is confusing when you are using data picker, for bootstrap datepicker you have to use following code:-

    $( ".datepicker" ).datepicker({
       format: 'yyyy-mm-dd'
    });
    

    and for jquery datepicker following code must be used:-

    $( ".datepicker" ).datepicker({
           dateFormat: 'dd-mm-yy'
        });
    

    So you must be aware which date picker you are using, that is ultimately solve your issue, Hope this hepls you.

    0 讨论(0)
  • 2021-02-03 20:33

    For Me i got same issue i resolved like this changed format:'dd/mm/yy' to dateFormat: 'dd/mm/yy'

    0 讨论(0)
  • 2021-02-03 20:33

    I have some problems with jquery mobile 1.4.5. For example it seems accepting format change only passing from "option". And there are some refresh problem with the calendar using "option". For all that have the same problems I can suggest this code:

    $( "#mydatepicker" ).datepicker( "option", "dateFormat", "dd/mm/yy" );
    $( "#mydatepicker" ).datepicker( "setDate", new Date());    
    $('.ui-datepicker-calendar').hide();
    
    0 讨论(0)
  • 2021-02-03 20:33

    "As with bootstrap’s own plugins, datepicker provides a data-api that can be used to instantiate datepickers without the need for custom javascript..."

    Boostrap DatePicker Documentation

    Maybe you want to set format without DatePicker instance, for that, you have to add the property data-date-format="DateFormat" to main Div tag, for example:

    <div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd">
        <div class="input-group-addon">
            <span class="glyphicon glyphicon-th"></span>
        </div>
    
        <input type="text" name="YourName" id="YourId" class="YourClass">
    </div>
    
    0 讨论(0)
提交回复
热议问题