Skip to content

Instantly share code, notes, and snippets.

@greglu
Created December 1, 2009 19:28
Show Gist options
  • Select an option

  • Save greglu/246554 to your computer and use it in GitHub Desktop.

Select an option

Save greglu/246554 to your computer and use it in GitHub Desktop.
public class Timestamp {
/**
* Convert the given date in hbase timestamp format.
* @param date to convert
* @return the timestamp
*/
public static long toHbaseTimestamp(Date date) {
return ((date.getTime() / 1000) << 32) + ((date.getTime() % 1000) * 1000);
}
/**
* Convert the given hbase timestamp into a Date object.
* @param timestamp hbase timestamp to convert
* @return a Date
*/
public static Date fromHbaseTimestamp(long timestamp) {
long seconds = timestamp >> 32;
long microseconds = timestamp & 0xFFFFFFFFL;
return new Date(seconds*1000 + microseconds/1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment