How to show dates with a format in uicalendar?

3

Hi, I've set up an angular calendar, it's a news programmer where people record what time they would be available or not at what time.

How can I show the date in the calendar in "1 mar 2017 12:00" format?

I know that with ng-repeat is to add date: 'MMMM dd yyyy' and it works, but on the calendar no, I have it so that when I click on a calendar item, I show the detailed information in a text box, with the full name and the dates ... I can not show it in that text box with the format.

  <div class="Calendar" ui-calendar='vm.uiConfig.calendar2' ng-model='vm.eventSources2'></div>
  <div class="col-md-5">
    <div ng-show="vm.selectedEvent" class="alert alert-success" style="margin-top:8px; font-size: 15px; font-weight: normal;">
      <h4 style="margin-top:0px; font-weight: bold;">Detalles:</h4>
      <p>{{vm.selectedEvent.titledetail}}</p>
      <p>{{vm.selectedEvent.dateini | date: 'dd MMMM yyyy, HH:mm'}}</p>
      <p>{{vm.selectedEvent.datefin | date: 'dd MMMM yyyy, HH:mm'}}</p>
      <p>Novedad: {{vm.selectedEvent.description}}</p>
    </div>
  </div>


</div>

I get it like this from: 2017-06-16T11:55:00-05:00

    
asked by BastianBurst 27.03.2017 в 16:17
source

2 answers

1

Good for those who want to do it I have already solved it, in the controller of the calendar there are some variables where I assign the values that come from the database or a value of the array that it brings, these are in the function that shows the data in the calendar in graphic form, what I did was apply the format in that part like this:

vm.eventSource.push({

dateini: ' desde: ' + $filter('date')(data[i].fechaIni, 'dd-MMMM-yyyy HH:mm'),

start: new Date(data[i].fechaIni),
  end: new Date(data[i].fechaFin),
  allDay: false,
  stick: true
  });

dateIni is a variable where I store the start date, then in the text box you call that dateIni.

    
answered by 27.03.2017 / 18:02
source
0

You can make a customized filter. A filter is a functionality that basically allows you to transform any data into anything.

You can use as input a string of characters 'month / year' or 'month' and get an arrangement in the output with the desired days.

I leave you a demo:

link

angular.module('app', [])
  .controller('CalendarioCtrl', function() {
    var vm = this;
    vm.meses = [{
      nombre: 'Enero',
      numero: 1
    }, {
      nombre: 'Febrero',
      numero: 2
    }, {
      nombre: 'Marzo',
      numero: 1
    }, {
      nombre: 'Abril',
      numero: 4
    }, {
      nombre: 'Mayo',
      numero: 5
    }, {
      nombre: 'Junio',
      numero: 6
    }, {
      nombre: 'Julio',
      numero: 7
    }, {
      nombre: 'Agosto',
      numero: 8
    }, {
      nombre: 'Septiembre',
      numero: 9
    }, {
      nombre: 'Octubre',
      numero: 10
    }, {
      nombre: 'Noviembre',
      numero: 11
    }, {
      nombre: 'Diciembre',
      numero: 12
    }];
    vm.semana = ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'];
  })
  .filter('calendario', function() {
    return function(input) {
      if (input) {
        var result = [];
        var year = moment().year();
        var startDay = moment(input + '/01/' + year);
        var endDay = startDay.clone().endOf('month');
        var prefix = startDay.weekday();
        var dayPrevMonth = startDay.clone().day(0).date();
        var endPrevMonth = startDay.clone().day(0).endOf('month').date();
        if (endPrevMonth - dayPrevMonth < 7) {
          for (var i = dayPrevMonth; i <= endPrevMonth; i++) {
            result.push({
              day: i,
              current: false
            });
          }
        }
        var days = startDay.daysInMonth();
        for (var i = 0; i < days; i++) {
          result.push({
            day: i + 1,
            current: true
          });
        }

        var endNextWeek = endDay.clone().day(7).date();
        for (var i = 1; i < endNextWeek; i++) {
          result.push({
            day: i,
            current: false
          });
        }

        return result;
      }
    };
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<div ng-app="app" ng-controller="CalendarioCtrl as vm">
  <select ng-options="mes.numero as mes.nombre for mes in vm.meses" ng-model="vm.selected">
  </select>
  <br>
  <br>
  <div ng-if="vm.selected">
    <ul class="calendar header">
      <li class="day" ng-repeat="dia in vm.semana">{{dia}}</li>
    </ul>
    <ul class="calendar">
      <li class="day" ng-class="{other: !item.current}" ng-repeat="item in vm.selected | calendario track by $index">
        {{item.day}}
      </li>
    </ul>
  </div>
</div>
    
answered by 27.03.2017 в 18:06