Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eonasdan Bootstrap datetimepicker format

How to set a format in bootstrap 3 datetimepicker. I want the format "dd/MM/yyyy hh:mm" and I dont want "AM" and "PM". For that in which language I can use here. The following fiddle How can I do this?

http://jsfiddle.net/Eonasdan/0Ltv25o8/

$('#datetimepicker1').datetimepicker({
 
    format : "dd/MM/yyyy hh:mm",
    
});
<!-- padding for jsfiddle -->
<div class="row">
    <div class="col-md-12">
        

        <div class="form-group">
            <div class="input-group date" id="datetimepicker1">
                <input type="text" class="form-control" />	<span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
            </div>
        </div>        
    </div>
</div>
like image 597
sathish kumar Avatar asked Apr 01 '15 07:04

sathish kumar


2 Answers

$('#datetimepicker1').datetimepicker({format : "DD/MM/YYYY hh:mm"});
$('#datetimepicker2').datetimepicker({format : "DD/MM/YYYY hh:mm"});
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
</head>
<br/>
<!-- padding for jsfiddle -->
<div class="row">
    <div class="col-md-12">
         <h6>datetimepicker1</h6>

        <div class="form-group">
            <div class="input-group date" id="datetimepicker1">
                <input type="text" class="form-control" />	<span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
            </div>
        </div>
         <h6>datetimepicker2</h6>

        <input type="text" class="form-control" id="datetimepicker2" />
    </div>
</div>

I'm not sure why yours isn't working, using dd/MM/yyyy hh:mm gives the output We/04/yyyy 08:43. If you want the output to be for example 01/03/2015 12:01 you need to set format : "DD/MM/YYYY hh:mm". For more information on format options take a look at the momentjs documentation.

See updated jsfiddle

You need to make sure that you include all of the necessary css and js files that the datetimepicker needs to work. You also need momentjs and jquery to load first. See code snippet.

like image 104
br3w5 Avatar answered Nov 18 '22 17:11

br3w5


adding data-date-format="YYYY-MM-DD HH:mm" in the input tag also works.

<input type="text" class="form-control" data-date-format="YYYY-MM-DD HH:mm"/>
like image 6
SuperNova Avatar answered Nov 18 '22 16:11

SuperNova