I found this code:
long timeStampSeconds = ChronoUnit.MICROS.between(Instant.EPOCH, Instant.now());
but when I converted this back to fetch month and year using the following code, it gives the wrong output.
try {
epochLong = Long.parseLong(epoch);
} catch (RuntimeException e) {
//Log exception
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(epochLong);
String month = String.valueOf(cal.get(Calendar.MONTH));
String year = String.valueOf(cal.get(Calendar.YEAR));
//print month and year
Any pointers as to how I can generate this in microseconds and get the month and year back right? Please help.