Angular-calendar: 24-hour clock

Created on 26 Oct 2016  路  13Comments  路  Source: mattlewis92/angular-calendar

Is it possible to change the time and clock of the calendar to 24-hour clock format?

For example:

13:00 instead 1PM

23:00 instead of 11PM

Most helpful comment

You can use DI to handle this:

import {CalendarNativeDateFormatter, DateFormatterParams, CalendarModule} from 'angular2-calendar';

class CustomDateFormatter extends CalendarNativeDateFormatter {

  public dayViewHour({date, locale}: DateFormatterParams): string {
    // change this to return a different date format
    return new Intl.DateTimeFormat(locale, {hour: 'numeric'}).format(date);
  }

}

@NgModule({
  import: [CalendarModule],
  providers: [
    CalendarEventTitleProvider, 
     {provide: CalendarDateFormatter, useClass: CustomDateFormatter}
  ]
})
class ModuleThatUsesTheCalendar{}

All 13 comments

You can use DI to handle this:

import {CalendarNativeDateFormatter, DateFormatterParams, CalendarModule} from 'angular2-calendar';

class CustomDateFormatter extends CalendarNativeDateFormatter {

  public dayViewHour({date, locale}: DateFormatterParams): string {
    // change this to return a different date format
    return new Intl.DateTimeFormat(locale, {hour: 'numeric'}).format(date);
  }

}

@NgModule({
  import: [CalendarModule],
  providers: [
    CalendarEventTitleProvider, 
     {provide: CalendarDateFormatter, useClass: CustomDateFormatter}
  ]
})
class ModuleThatUsesTheCalendar{}

Hi @mattlewis92, Can you please help me to implement this? I can't get it to work..

It seems like you need to force the locale to make this work, using canadian seems to do the trick: http://plnkr.co/edit/INtKoU2Tony08Soqy8x7?p=preview

@mattlewis92 Thank you for the fast response!

@mattlewis92, One more thing please - why I don't see the events in the Calendar .. ?
http://plnkr.co/edit/Ve1VQN3AjoiYNDM3RRto?p=preview

There was no color set on each event (check the console output in your plunker). TS should complain about the missing properties in a real app though. http://plnkr.co/edit/b4fbs11FBOeldGifjmpt?p=preview

@mattlewis92 You are rock 馃憤 Thanks

Error in importing CalendarEventTitleProvider in my case.

Hi, how to calculate no of days and hours from startDate and endDate when we add new event

@mattlewis92
I need to show only from 09:00 to 17:00 hours in day view?
how can I achieve this?

@harsh-khandelwalcs i think you can use daystartHour and dayEndHOur Attribute of the Calendar so for example:

<mwl-calendar-day-view
                            [viewDate]="viewDate"
                            [events]="events"
                            [locale]="locale"
                            [weekStartsOn]="startWeek"
                            [dayStartHour]="9"
                            [dayEndHour]="17">
    </mwl-calendar-day-view>

That would be a day view only from 09:00 to 17:00 hours

Elegant solution, thank you very much!

For >= angular 9, the CustomDateFormatter should have a @Injectable() annotation - for >= angular 10, it must have the annotation.

@Everyone Hi, How can I add an event with startTime as 10:25PM and endTime as 11:15PM, then plot it on the calendar day view to show that exact time on the calendar as an event. The view is in THIS format. i.e 1PM = 13:00

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chaouiy picture chaouiy  路  3Comments

sylvain-fr picture sylvain-fr  路  3Comments

nguyendo picture nguyendo  路  3Comments

Novabllast picture Novabllast  路  3Comments

PrasannaKolla picture PrasannaKolla  路  4Comments