xxxxxxxxxx
import java.util.Calendar;
import java.util.Date;
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
xxxxxxxxxx
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
public class CurrentDateTimeExample1 {
public static void main(String[] args) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
}
}
xxxxxxxxxx
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date today = new Date();
System.out.println(formatter.format(today));
xxxxxxxxxx
import java.util.Date;
public class Main {
public static void main(String[] args) {
// Get the current time in milliseconds
long currentTimeMillis = System.currentTimeMillis();
// Create a Date object using the current time
Date currentDate = new Date(currentTimeMillis);
// Print the current time
System.out.println(currentDate);
}
}
xxxxxxxxxx
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
System.out.println(formatter.format(date));
// ------------------------
System.out.println(LocalDate.now());
xxxxxxxxxx
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date currentDate = new Date();
System.out.println(currentDate);
}
}
xxxxxxxxxx
import java.util.Calendar;
Date currentTime = Calendar.getInstance().getTime();
xxxxxxxxxx
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
public class CurrentDateTimeExample1 {
public static void main(String[] args) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
}
}