Created
April 1, 2014 04:42
-
-
Save mariuswatz/9907831 to your computer and use it in GitHub Desktop.
Convert Chrome (webkit) timestamp to Unix timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
Thanks! It works