-->

Eonasdan Bootstrap datetimepicker format

2019-04-01 17:55发布

问题:

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>

回答1:

$('#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.



回答2:

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"/>