I have the following method that has been for a very long time in a legacy codebase.
public static Calendar nowAsCalendar(String timeZone){
Calendar FDRCal = GregorianCalendar.getInstance(timeZone);
FDRCal.setTime(now());
Calendar cal = Calendar.getInstance();
cal.set(1, FDRCal.get(1));
cal.set(2, FDRCal.get(2));
cal.set(5, FDRCal.get(5));
cal.set(11, FDRCal.get(11));
cal.set(12, FDRCal.get(12));
cal.set(13, FDRCal.get(13));
cal.set(14, FDRCal.get(14));
}
We are setting a brand new Calendar instance cal that uses the default timezone so I think it should break as we are not setting the timezone in the new Calendar instance. Am I overlooking something?. What is the best way to set the current date with a timezone?