Get just the hour of day from DateTime using either 12 or 24 hour format as defined by the current c

Posted by InvisibleBacon on Stack Overflow See other posts from Stack Overflow or by InvisibleBacon
Published on 2010-06-10T13:55:58Z Indexed on 2010/06/10 14:02 UTC
Read the original article Hit count: 220

Filed under:
|
|
|

.Net has the built in ToShortDateString() function for DateTime that uses the CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern format. It returns something like this for en-US: "5:00 pm". For a 24 hour culture such as de-DE it would return "17:00".

What I want is a way to just return just the hour (So "5 pm" and "17" in the cases above) that works with every culture. What's the best/cleanest way to do this?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET