I. Get the current system time and date and format the output:
Import Java.util.Date;
Import Java.text.SimpleDateFormat;
public class Nowstring {
public static void Main (string[] args) {
SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//Set Date format
System.out.println (Df.format (new Date ()));//new Date () to get the current system time
}
}
Two.
Calendar C = calendar.getinstance ();//Can be modified individually for each time domain
int year = C.get (calendar.year);
int month = C.get (calendar.month);
int date = C.get (calendar.date);
int hour = C.get (Calendar.hour_of_day);
int minute = C.get (Calendar.minute);
int second = C.get (Calendar.second);
int Week=c.get (Calendar.day_of_week);
SYSTEM.OUT.PRINTLN (Year + "/" + month + "/" + Date + "" +hour + ":" +minute + ":" + second);
}
}
Two ways to get the current system time in Java