I'm trying to create list of hours my code like
var hours = Enumerable.Range(00, 24).Select(i => i.ToString("D2")));
it generates something like this in 24 hour format but actually i need same thing not on 24 hours but 12 like after with AM PM postfix
what is the best way to generate hour list with 00.00 AM/PM formatted
Thanks
You can create a DateTime instance then use ToString format of hh.mm tt.
var hours = Enumerable.Range(00, 24)
.Select(i => new DateTime(2000,1,1,i,0,0).ToString("hh.mm tt"));
You need to execute the query using something like ToArray() to get the result since the behavior of linq is deferred execution.
var hours = Enumerable.Range(00, 24).Select(i => (DateTime.MinValue.AddHours(i)).ToString("hh.mm tt"));
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