Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Forked from mariuswatz/ChromeTimestamp.java
Created October 28, 2022 07:01
Show Gist options
  • Save jpluimers/7f55880102d22b20c1aff1bad32f239d to your computer and use it in GitHub Desktop.
Save jpluimers/7f55880102d22b20c1aff1bad32f239d to your computer and use it in GitHub Desktop.
Convert Chrome (webkit) timestamp to Unix timestamp
// Marius Watz - http://workshop.evolutionzone.com
//
// Convert webkit timestamps to the UNIX timestamps used in Java.
// Written to deal with timestamps from the Chrome browser history
// database (stored as SQLite)
import java.util.*;
import java.text.SimpleDateFormat;
SimpleDateFormat df=new SimpleDateFormat("YYYY MMM dd HH:mm");
// webkit timestamps use Jan 1, 1601 as epoch start, UNIX timestamps
// start at Jan 1, 1970. this constant represents the difference
// in milliseconds.
long CHROMEEPOCHSTART=11644473600000l;
long chromeTime(long t) {
// wekbit timestamps are in microseconds, hence t/1000
return (t/1000-CHROMEEPOCHSTART);
}
String chromeTimeStr(long t) {
Date d=new Date(chromeTime(t));
return df.format(d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment