I want to get the current hour number with 0-24
from System.DateTime.Now.Hour
.
I am not sure if it will return an integer between 0-12
or 0-24
.
How do I make sure I will get an integer between 0-24
?
DateTime.Hour Property
The value of the Hour property is always expressed using a 24-hour clock. To retrieve a string that represents the hour of a date and time using a 12-hour clock, call the DateTime.ToString(String) or DateTime.ToString(String, IFormatProvider) method with the "h" custom format specifier. For example:
and
The hour component, expressed as a value between 0 and 23.
If you are trying to get a specific string version of a DateTime object I suggest using either a custom date and time format string or a standard date and time format string.
I usually use dateTimeVar.ToString("yyyy/MM/dd HH:mm:ss.ffff zzz");
though you may want K
instead of zzz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With