When I do this:
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(9999, 11, 31, 0, 0, 0);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy HH.mm.ss.SSSSSSSSS a");
String date = formatter.format(c.getTime());
assertEquals("31-Dec-99 00.00.00.000000000 AM", date);
I get this: 30-Dec-99 18.00.00.000000318 PM
How do I get the time I want?
You need to set the formatter’s time zone as well before performing the format.
Otherwise it will use the platform default time zone.
Unrelated to the concrete problem, the calendar doesn’t hold nano seconds, so that part may still be a bit off after formatting.