Reputation: 1
Can anyone tell me how to change the time format in a DataGridView ?
My requirement is to have a 12 hours format with AM, PM. For example 10:23 am, 10:23 pm. I have tried this:
datagridview.column(6).DefaultCellStyle.Format = "hh:mm"
DGVDWA.Columns(6).DefaultCellStyle.Format = "hh:mm:ss tt" but it shows an error popup (it worked in VB.NET Windows form app).
Upvotes: 0
Views: 4153
Reputation: 197
Try adding "tt" to the end of your code to set the format:
datagridview.column(6).DefaultCellStyle.Format = "hh:mm:ss tt"
This should display the time as 10:59:01 PM. Remove the :ss if you do not want to display seconds.
More information can be found here: MSDN
Upvotes: 1