So doing my first year of software engineering at Uni and am having a little trouble with the old Java,
Basically I need to use the Calendar class to call todays date, and then store it in a variable, Iv stumbled upon this bit of code but don’t really understand what’s going on enough to be able to re-write it to do what i want it to do, If someone could help me out without giving the answer (don’t learn that way!) And maybe point me in the right direction would be much appreciated,
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Main {
public void convertDateToString() {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
try {
System.out.println("Today: " + dateFormat.format(calendar.getTime()));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Main().convertDateToString();
}
}
As it stand this prints todays date in a console window, But I don't want to use it, I want to fully understand what its doing then build something up myself,
Hope someone is able to help me out!
Cheers