Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to ignore the seconds ToShortTimeString

Tags:

c#

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 ?

like image 542
VeecoTech Avatar asked Jun 10 '11 07:06

VeecoTech


2 Answers

use Value.ToString("HH:mm") to always get the same format, because ToShortTimeString uses the format defined on the PCs culture.

like image 139
Christoph Fink Avatar answered Nov 06 '22 21:11

Christoph Fink


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")
like image 5
Vijay Sirigiri Avatar answered Nov 06 '22 21:11

Vijay Sirigiri