Timespan formatting in Excel

邮差的信 提交于 2021-02-20 02:34:08

问题


I'm currently using the custom format, m:ss.00, and it works perfectly for any times that exceed one minute, e.g. 1:02.47. However, if I enter a time less than a minute, e.g. 57.66, it gets transformed into 50:24.00. I can get around this by entering 0:57.66, but I'd rather not have to always type the leading 0: and I don't want the leading 0: displayed anyway. I'd like for it to understand that if I skip the number followed by a colon part, to interpret this as no minutes and simply display 57.66.


回答1:


In Excel datetimes:

1   =   1 day

...therefore:

1 / 24            =  1 hour    =  0.04166667  formatted as m:ss.00 is 0:00.00

1 / 24 / 60       =  1 minute  =  0.00069444  formatted as m:ss.00 is 1:00.00

1 / 24 / 60 / 60  =  1 second  =  0.00001157  formatted as m:ss.00 is 0:01.00

So if you have a number of seconds like 50.24, you can convert it to Excel DateTime by dividing it by x/24/60/60 which is the same as x/86400.

This will convert it to seconds.

The reason your method works if it's more than a minute is basically through the process of elimination. A "real number" like 50.24 just looks like a number since it has no : colon or anything else to distinguish it as a datetime. Entering intead 0:50.24 will force Excel to recognize it as a datetime.

Similarly, entering these dates:

12/01/1999
01/12/1999

...could have varying results (January 12, 1999 or December 1, 1999) depending on your regional settings (whether your country uses M/D/Y or D/M/Y), however, entering either of these:

01/13/1999
13/01/1999

...will both be interpreted as "January 1, 1999" since Excel was able to eliminate other possibilities (since there's no 13th month).


More Information:

  • Office.com : Working with Dates & Times in Excel

  • Office.com : Change the Windows Regional Settings

  • Wikipedia : Date format by Country

  • Office.com : Add or Subtract Time



来源:https://stackoverflow.com/questions/50317179/timespan-formatting-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!