开发者

Need 12-h time formatting in Excel

Consider an Excel sheet with one column of bad data. We have a table that can be used to correct the data. My code runs it by writing a new sheet containing the old sheet plus adding new columns of correct data for them to compare.

This date is fine and works but it makes the date/time into a format with 24-h time.

How can this be changed t开发者_运维技巧o use the preferred format?

newSheet.Cells[i + 2, 3] = drugorder.DATE;
newSheet.Cells[i + 2, 3].NumberFormat = "m/d/yyyy h:mm"; 


Apparently, the h specifier in an Excel date format will only use 12-hour time if you include an AM/PM specifier in the number format as well.

The seemingly logical .NumberFormat = "m/d/yyyy h:mm" produces:

2/13/1922 5:19
5/17/1927 21:13

While .NumberFormat = "m/d/yyyy h:mm AM/PM" produces the intended:

2/13/1922 5:19 AM
5/17/1927 9:13 PM
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜