Skip to content

Instantly share code, notes, and snippets.

@migueldiab
Forked from brunoborges/RandomShiftOnDate.java
Created March 1, 2014 18:59
Show Gist options
  • Save migueldiab/9295332 to your computer and use it in GitHub Desktop.
Save migueldiab/9295332 to your computer and use it in GitHub Desktop.
private static Random random = new Random();
private static int MIN = 60 * 1000;
private static Calendar cal = Calendar.getInstance();
public static Date randomShiftOnDate(Date someDate) {
int randomValue = (random.nextInt(61) - 30) * MIN; // +/- 30 min.
long time = someDate.getTime() + randomValue;
Date result;
synchronized (cal) {
result = cal.setTimeInMillis(time).getTime();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment