C# DateTime to Excel Time

Viewed 46

How can I create a column that displays only the time and not the date and time in Excel?\

This is what is displayed in Excel

13.09.2022  12:24:16

Setting the NumberFormat with "hh:mm:ss" is not working

List<DateTime> time = new List<DateTime>();

worksheet = workbook.Worksheets.Add();
worksheet.Range[$"$A$1:$A{time.Count}"].Value = excel.Application.WorksheetFunction.Transpose(time.ToArray());
1 Answers

I solved it by converting DateTime to a double with a range from 0 to 1

time = hour / 24.0 + minute / 24.0 / 60.0 + second / 24.0 / 60.0 / 60.0
Related