How to parse Chrome bookmarks "date_added" value to a Date How to parse Chrome bookmarks "date_added" value to a Date google-chrome google-chrome

How to parse Chrome bookmarks "date_added" value to a Date


The Chrome bookmarks time value is microseconds from an epoch of 1601-01-01T00:00:00Z. To convert to a Date:

  1. Divide by 1,000 to get milliseconds
  2. Adjust to an epoch of 1970-01-01T00:00:00Z
  3. Pass the resulting value to the Date constructor

E.g.

var timeValue = '13170147422089597';new Date(Date.UTC(1601,0,1) + timeValue / 1000); // 2018-05-07T06:17:02.089Z

Storing the value Date.UTC(1601,0,1) as a constant (-11644473600000) and converting to a function gives:

function chromeTimeValueToDate(tv) {  var epoch = -11644473600000;  return new Date(epoch + tv / 1000);}// Example['13170147422089597', '13150297844686316', '13115171381595644'].forEach( tv => {   console.log(chromeTimeValueToDate(tv))});