Skip to main content

How to: Display Appointments in Military Time

  • 2 minutes to read

This document illustrates the use of AppointmentFormatStringService to change the display format of appointment’s Appointment.Start and Appointment.End values. The time will be expressed in military style, that is, using a unique two-digit number to identify each of the 24 hours in a day, leading zero and no spaces between hours and minutes.

To accomplish this, substitute the service with a custom service, containing method overrides. The list of methods which can be overridden is found in the Formatting Services topic.

AppointmentFormatStringService

The following code implements a descendant class which displays military time and replaces the required service with a custom descendant:

IAppointmentFormatStringService oldService = scheduler.GetService<IAppointmentFormatStringService>();
if (oldService != null)
{
    MyAppointmentFormatStringService newService = new MyAppointmentFormatStringService(oldService);
    scheduler.RemoveService(typeof(IAppointmentFormatStringService));
    scheduler.AddService(typeof(IAppointmentFormatStringService), newService);
}
scheduler.ActiveView.LayoutChanged();
public class MyAppointmentFormatStringService : AppointmentFormatStringServiceWrapper
{
    public MyAppointmentFormatStringService(IAppointmentFormatStringService service)
        : base(service) { }
    public override string GetVerticalAppointmentStartFormat(
        IAppointmentViewInfo aptViewInfo)
    {
        return "{0: HHmm:ss - 'VerticalAppointmentStart'}";
    }
    public override string GetVerticalAppointmentEndFormat(
        IAppointmentViewInfo aptViewInfo)
    {
        return "{0: HHmm:ss - 'VerticalAppointmentEnd'}";
    }
    public override string GetHorizontalAppointmentEndFormat(
        IAppointmentViewInfo aptViewInfo)
    {
        return "{0: HHmm - 'HorizontalAppointmentEnd'}";
    }
    public override string GetHorizontalAppointmentStartFormat(
        IAppointmentViewInfo aptViewInfo)
    {
        return "{0: HHmm - 'HorizontalAppointmentStart'}";
    }
    public override string GetContinueItemStartFormat(IAppointmentViewInfo aptViewInfo)
    {
        return "{0: HHmm MMM dd - 'ContinueItemStart'}";
    }
    public override string GetContinueItemEndFormat(IAppointmentViewInfo aptViewInfo)
    {
        return "{0: HHmm MMM dd - 'ContinueItemEnd'}";
    }
}