问题描述
在 Excel 中表示 DateTime
的最佳方式是什么?我们使用 Syncfusions Essential XlsIO 将值输出到效果很好的 Excel 文档.但我不知道如何在列中显示 DateTime
.也不是直接在 Excel 中自己做.不可能吗?我是否必须使用单独的日期和时间列?我真的希望我没有,因为它会破坏排序等......除非 Excel 有一些聪明的方法来解决这个问题......
What is the best way of representing a DateTime
in Excel? We use Syncfusions Essential XlsIO to output values to an Excel document which works great. But I can't figure out how to display a DateTime
in a column. Not when doing it myself directly in Excel either. Is it impossible? Do I have to use a separate date and a time column? I really wish I didn't, cause it kind of breaks sorting etc... unless Excel have something clever going on to fix that...
推荐答案
Excel 中日期时间的基础数据类型是 64 位浮点数,其中一天的长度等于 1
和1st Jan 1900 00:00
等于 1
.所以 11th June 2009 17:30
大约是 39975.72917
.
The underlying data type of a datetime in Excel is a 64-bit floating point number where the length of a day equals 1
and 1st Jan 1900 00:00
equals 1
. So 11th June 2009 17:30
is about 39975.72917
.
如果单元格包含这样的数值,只需将日期时间格式应用于单元格即可将其转换为日期时间.
If a cell contains a numeric value such as this, it can be converted to a datetime simply by applying a datetime format to the cell.
因此,如果您可以使用上述公式将日期时间转换为数字,请将它们输出到相关单元格,然后将单元格格式设置为适当的日期时间格式,例如yyyy-mm-dd hh:mm:ss
,那么应该可以实现你想要的.
So, if you can convert your datetimes to numbers using the above formula, output them to the relevant cells and then set the cell formats to the appropriate datetime format, e.g. yyyy-mm-dd hh:mm:ss
, then it should be possible to achieve what you want.
还有 Stefan de Bruijn 指出存在一个错误在 Excel 中,它错误地假设 1900 年是闰年,因此您在进行计算时需要考虑到这一点(维基百科).
Also Stefan de Bruijn has pointed out that there is a bug in Excel in that it incorrectly assumes 1900 is a leap year so you need to take that into account when making your calculations (Wikipedia).
这篇关于如何在 Excel 中表示日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!