How To Convert Firefox Bookmark Dates Using Groovy/Java

Firefox offers us two ways to keep our bookmarks, 1: backup as a json formatted file or 2: export as an html file.

This tip is for the json backup crowd 🙂

When we backup our bookmarks from Firefox, they come out formatted as json. The dates found therein are stored in what’s known as epoch dates ( read this ) though include millesecond precision – meaning 1,000 trailing milliseconds. So, for example, the firefox bookmark lastModified date of  1366313580447014 is really just 1366313580447. So when we write code, we divide by 1,000 to remove that part. My groovy code sample seemed to work when it looked like this :

def convertDate(def epoch)
{
     long dv = epoch / 1000; // divide by 1,000 to avoid milliseconds 
     String dt = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm:ss").format(new java.util.Date (dv)); 
     // to get epoch date: 
     // long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() * 1000; 
     return dt; 
} // end of def

So for a test sample, i did a firefox backup to get bookmarks-2013-04-29.json. Then added some groovy sugar to parse the text with json slurper.

json.lastModified :1366313580447014
convert from epoch date:18/Apr/2013 21:33:00

from :
println “convert from epoch date:”+convertDate(json.lastModified)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s