简体   繁体   中英

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. 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. 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." and I was told it's a Microsoft timestamp.

This is the timestamp format of Microsoft Excel . It is some kind of special. The 1.1.1900 0:0 is 1.0. The 2.1.1900 0:0 is 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.

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

The result is an UNIX timestamp and can for example be passed to the constzructor of Date .

var realDate = new Date(convertExcelTimeToUnix(excelTime))

Looks like it's the number of days elapsed since 01/01/1900.

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

will do it in javascript.

The extra multipliers are fairly obviously to convert it into the milliseconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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