Skip to content

Instantly share code, notes, and snippets.

@KodeSeeker
Created April 20, 2015 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KodeSeeker/281590886d348957dc01 to your computer and use it in GitHub Desktop.
Save KodeSeeker/281590886d348957dc01 to your computer and use it in GitHub Desktop.
Cassandra convert from UID to Date
public static void main (String... args){
UUID uid = UUIDs.timeBased();
long time = getTimeFromUUID(uid);
Date date = new Date(time);
System.out.println(date);
}
static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
public static long getTimeFromUUID(UUID uuid) {
return (uuid.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) / 10000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment