Alex Rivera | Logout

how to ignore the seconds ToShortTimeString

Asked 2011-06-10T07:29:45.257
10

My datetime is showing me the seconds eventhough i have put as this
TimeSlotFrom = Value.ToShortTimeString();

I can view it from my laptop only HH:mm. However when read from your client's pc, it show it as HH:mm:ss.

does it relates to the time format used in my client's pc? How do i handle this to just show HH:mm ?

c#
Edit
Report

2 Answers

5

From MSDN: DateTime.ToShortTimeString Method

The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.ShortTimePattern property associated with the current thread culture.

DateTimeFormatInfo.ShortTimePattern 

Your applications are recommended to set the short time pattern to the exact value of interest, instead of attempting to have the time separator replaced. For example, to obtain the pattern h-mm-ss, the application should set "h-mm-ss" specifically.

Or the simplest is to use this instead

TimeSlotFrom = Value.ToString("HH:mm tt")
answered 2011-06-10T07:35:58.730
0

http://blog.stevex.net/string-formatting-in-csharp/ is a good reference on string formatting.

answered 2011-06-10T07:34:20.623

Your Answer