Skip to content

Instantly share code, notes, and snippets.

@FoxIvan
Created August 4, 2016 18:05
Show Gist options
  • Save FoxIvan/0ce9b019528aa74ba64e569ef3b2e500 to your computer and use it in GitHub Desktop.
Save FoxIvan/0ce9b019528aa74ba64e569ef3b2e500 to your computer and use it in GitHub Desktop.
Get an accurate date from now on
Date dNow = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(dNow);
calendar.add(Calendar.MONTH, -2);
calendar.add(Calendar.DAYOFMONTH, -2);
Date dBefore = calendar.getTime();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startDate = sdf.format(dBefore);
String endDate = sdf.format(dNow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment