开发者

How can I reverse the Excel time function to hour, minute and second?

In Excel I use the following function

Time( hour, minute, second )

And it appears开发者_如何学C in the following format

11:07:27 AM

However when I treat excel as an ODBC data source and use getString to retrieve the value, it comes out something like

0.45856481481

How can I reverse this back to hours, minutes and seconds?


For starters, see the SO question/answer for Excel parsing (xls) date error for an explanation of date time formats in Excel; this will explain where that number you are seeing is coming from. Your problem is just a variation; numbers to the right of a decimal are an indicator of time measured as a fraction of a day.

I am going to assume you are using Java (based on the clues in your post), though your post isn't tagged with a programming language.

You should not use getString() to return a date value because this method simply returns the string representation of the underlying data (in this case, the number); you should use getDate() instead, which will translate the number into a date.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜