简体   繁体   English

这是什么类型的时间戳以及如何使用 JavaScript 将其转换为人类可读的

[英]What type of timestamp is this and how do I convert it to human-readable using JavaScript

I've been given hundreds of CSV files, all with timestamps I don't recognise.我收到了数百个 CSV 文件,所有文件都带有我不认识的时间戳。 I've been trying my best to find what it is and try to convert them using JavaScript but so far I've had no luck.我一直在尽力找到它是什么,并尝试使用 JavaScript 转换它们,但到目前为止我还没有运气。 All the instructions I've been given are this: "The Timestamp 39845.03 is a representation of the date 01/02/2009 and the time 00:45."我得到的所有指令都是这样的:“时间戳 39845.03 表示日期 01/02/2009 和时间 00:45。” and I was told it's a Microsoft timestamp.有人告诉我这是微软的时间戳。

This is the timestamp format of Microsoft Excel .这是Microsoft Excel的时间戳格式。 It is some kind of special.这是某种特殊的。 The 1.1.1900 0:0 is 1.0. 1.1.1900 0:0 是 1.0。 The 2.1.1900 0:0 is 2.0. 2.1.1900 0:0 是 2.0。

The part behind the comma expresses the time.逗号后面的部分表示时间。

On ExcelTips: Unix timestamps to Excel they give a formular that just needs to be inverted to accomblish the conversion.ExcelTips: Unix 时间戳到 Excel 上,他们提供了一个公式,只需反转即可完成转换。

function convertExcelTimeToUnix(excelTime) {
    return (excelTime - 25569) * 86400;
}

The result is an UNIX timestamp and can for example be passed to the constzructor of Date .结果是一个 UNIX 时间戳,例如可以传递给Date的构造函数。

var realDate = new Date(convertExcelTimeToUnix(excelTime))

Looks like it's the number of days elapsed since 01/01/1900.看起来这是自 1900 年 1 月 1 日以来经过的天数。

 var date = new Date('01 jan 1900');
 date.setTime(date.getTime() + 39845.03 * 24 * 60 * 60 *1000);

will do it in javascript.将在 javascript 中进行。

The extra multipliers are fairly obviously to convert it into the milliseconds.额外的乘数很明显将其转换为毫秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM