如何在Excel中表示DateTime [英] How to represent a DateTime in Excel

查看:622
本文介绍了如何在Excel中表示DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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中datetime的底层数据类型是64位浮点数,其中一天的长度等于1,1900年1月1日00:00等于1.因此,2009年6月11日17:30约为39975.72917

The underlying datatype 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.

如果一个单元格包含一个数字值,例如,可以通过向单元格应用datetime格式将其转换为datetime。

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.

因此,如果您可以使用上述公式将数据转换为数字,则将其输出到相关单元格,然后将单元格格式设置为适当的datetime格式,例如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 acheive what you want.

另外 Stefan de Bruijn 指出,Excel中有一个错误,因为它错误地假设1900是闰年,所以你需要在进行计算时考虑到这一点( Wikipedia )。

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中表示DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆