how to get the 12 hour date from DateTime
How about:
DateTime.Hour % 12
That will give 0-11 of course... do you want 1-12? If so:
((DateTime.Hour + 11) % 12) + 1
I don't think there's anything simpler built in...
DateTime.Now.ToString("hh"); --> Using this you will get "06" for 18h.
I don't know of any built in method, but you can always add an extension method to accomplish this.
Of course, you could always replace the code with the way you want to accomplish it.
public static class Extension
{
public static int GetTwelveCycleHour(this DateTime dateTime)
{
if (dateTime.Hour > 12)
{
return dateTime.Hour - 12;
}
return dateTime.Hour;
}
}