5 Answers, 1 is accepted
The only way to make an appointment appear in 24hour or 12hour format is to modify the Culture property of RadScheduler. This is because we format Appointment ‘s Start and End time using the ShortTimePattern and the culture settings used in RadScheduler. We do the string formatting using a code like this:
DateTimeFormatInfo info = new DateTimeFormatInfo(); |
string str = info.ShortTimePattern + " tt"; |
CultureInfo culture = base.Scheduler.Culture; |
string startString = this.Appointment.Start.ToString(str, culture); |
string EndString = this.Appointment.End.ToString(str, culture); |
As you can see, the result string value depends on the culture and ShortTimePattern only.
All the best,
Nikolay
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
string str = info.ShortTimePattern + " tt";
pulls the ShortTimePattern from "CultureInfo.InvariantCulture" which is strictly readonly.
Can you give an example of how I should go about changing the culture in order to change the times to 12-hr?
Thanks for your help,
Marcus
Hi Marcus,
We pass RadScheduler's culture parameter when we do datetime formatting. This will format the time string according to specific culture settings.
To change appointment's start and end time formatting you should use RadScheduler's Culture property.
To change the culture you can use a code snippet like this:
this.radScheduler1.Culture = new System.Globalization.CultureInfo("en-US"); |
I hope this helps. If you have additional questions, feel free to contact me.
Kind regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
In your code you show the following:
DateTimeFormatInfo info = new DateTimeFormatInfo();
string str = info.ShortTimePattern + " tt";
When you get the ShortTimePattern it is returning HH:mm (HH = 24 hour format, we need it to be hh which is 12 hour format) and then you append ‘tt’ to it to get the am/pm. Then you get the culture from the scheduler. The culture is then applied in the ToString using the datetime format that was created in the code above. In doing so the only effect the culture has on the formatted output is setting the correct am/pm for that culture, not the 12 hour time format since that is what we are trying to change.
I am sure you have good reason for the code above, but I don’t understand why you couldn’t have used the ShortTimePattern from the culture instead of the new DateTimeFormatInfo. If you did we could easily modify the culture and pass it into the scheduler and everything would work great, but the way you are currently doing this I don’t see any way of changing the ShortTimePattern. Is there any way of doing this? Could you please show us an example that works?
Hello Marcus,
We will consider changing the current behavior in the next version. We will add a property for a custom format string which will help you to easily modify the appointment's text. As soon as we change the current logic I will write you back and will describe you how the new behavior works. It is true that the only option at the moment which will affect the appointment's start and end datetime strings is changing the Culture property, but I agree that this is not enough.
Please contact me again if you have more questions. We will do our best to improve the logic for the upcoming releases.
Kind regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.