Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert numbers to time?

Is there a slick way to convert simple numbers (Army time included) to a time format (am, pm format)? I can do the tedious approach, but I was just wondering if there was another way

0800 => 8:00 am

2317 => 11:17 pm

like image 847
MrM Avatar asked Jun 11 '10 13:06

MrM


1 Answers

    DateTime dt = DateTime.ParseExact("0800", "HHmm", CultureInfo.InvariantCulture);
    string timestring = dt.ToString("h:mm tt");

See documentation for format codes.

like image 90
Brian Avatar answered Sep 22 '22 07:09

Brian