Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change language to Bootstrap Datetimepicker

I'm using the datetimepicker of Bootstrap, it's working pretty well. The thing is that it's in english, and I need it in spanish, I had read some post but nothing works to me. my HTML is defined as:

<div class="form-group">
  <div class='input-group date datepicker' data-date-startdate="{{$student->middle}}" name="datepicker" >
    <input type='text' class="form-control placementT" id="fecha">
    <span class="input-group-addon">
      <span class="glyphicon glyphicon-calendar"></span>
    </span>
  </div>
</div>

In the javascript, I have only one function related with the datetimepicker, this is:

$('.input-group.date').each(function() {
  $(this).datetimepicker().on('dp.hide',function (ev) {
    //something
  });
});

So, what should I add to change this to spanish?I had read that this is with locale.js but can I add the definition of days and months inside my javascript?

like image 525
Sredny M Casanova Avatar asked Dec 14 '15 15:12

Sredny M Casanova


People also ask

What is bootstrap DateTimePicker?

Bootstrap 5 DateTimepicker. DateTimepicker is a form that adds the function of selecting date and time without the necessity of using custom JavaScript code.

What is a date time picker?

The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.


1 Answers

You need to add locale, reference can be found here

For spanish locale: 'es'

Script

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/es.js"></script>

DateTimePicker in Spanish

$(document).ready(function(){
	$('.input-group.date').datetimepicker({
		locale: 'es',
	});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
<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.10.6/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/es.js"></script>
<br>
<div class="form-group">
     <div class='input-group date datepicker' name="datepicker" >
          <input type='text' class="form-control placementT" id="fecha">
             <span class="input-group-addon">
                   <span class="glyphicon glyphicon-calendar">
                   </span>
            </span>
      </div>
</div>
like image 124
Shehary Avatar answered Oct 04 '22 12:10

Shehary