xxxxxxxxxx
public static String findDay(int month, int day, int year) {
LocalDate ld=LocalDate.of(year,month,day);
return ld.getDayOfWeek().name();
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
import java.util.Date;
import java.text.SimpleDateFormat;
public class DateTimeExample {
public static void main(String[] args) {
// Create a Date object representing the current time
Date currentDate = new Date();
// Define the desired date and time format
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Format the Date object to the desired format
String formattedDateTime = dateFormat.format(currentDate);
// Print the formatted date and time
System.out.println("Current Date and Time: " + formattedDateTime);
}
}
xxxxxxxxxx
import java.util.Date;
import java.text.SimpleDateFormat;
public class DateTimeExample {
public static void main(String[] args) {
// Get the current date and time
Date currentDate = new Date();
// Format the date and time as a string
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = formatter.format(currentDate);
// Print the formatted date and time
System.out.println("Current date and time: " + formattedDate);
}
}
xxxxxxxxxx
import java.time.LocalDate;
public class LocalDateExample1 {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
LocalDate yesterday = date.minusDays(1);
LocalDate tomorrow = yesterday.plusDays(2);
System.out.println("Today date: " + date);
System.out.println("Yesterday date: " + yesterday);
System.out.println("Tomorrow date: " + tomorrow);
}
}
xxxxxxxxxx
import java.util.Date;
public class DateTimeExample {
public static void main(String[] args) {
// Create a new Date object
Date currentDate = new Date();
// Output the current date and time
System.out.println("Current Date and Time: " + currentDate);
}
}
xxxxxxxxxx
import java.time.LocalDate; // import the LocalDate class
public class Main {
public static void main(String[] args) {
LocalDate myObj = LocalDate.now(); // Create a date object
System.out.println(myObj); // Display the current date
}
}
xxxxxxxxxx
The T is just a literal to separate the date from the time, and the Z means "zero hour offset" also known as "Zulu time" (UTC). If your strings always have a "Z" you can use: SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss. SSS'Z'", Locale.US); format. setTimeZone(TimeZone.07-Dec-2011