My Technical Notes

Wednesday, 15 June 2016

Using DateTime.ToString to make string 12-hour Time String


string str = DateTime.Now.ToString("h:mm tt");

`h` returns the hours in 12 hour format. For example `18` will return `6`. `mm` returns the minutes. `tt` returns `AM` or `PM`.

No comments: