Created
December 1, 2009 19:28
-
-
Save greglu/246554 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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