DateTime now = DateTime.Now;
string time = now.ToString("h");
errors out saying I should parse the string first. The current time is 3 I don't want 03 I just want 3. "hh"
returns 03 but I can't simply use "h".
System.DateTime.Now.ToString("%h")
You have to specify that the format is custom.
It sounds like you want standard int
formatting. If so just call ToString
on the Hour
property
string time = now.Hour.ToString();
If you want 12 hour time then do the following
var hour = now.Hour > 12 ? now.Hour - 12 : now.Hour;
string time = hour.ToString();
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