Selenium -Java – Retrieving the current date time and updating them in different formats
Code:
package date;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
public class DateTime {
public static DateFormat simpleDF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
public static DateTimeFormatter dateTF = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
public DateTime(int i, int j, int k, int l, int m, int n) {
}
public static void main(String[] args) {
Date date = new Date();
System.out.println("1. Simple Date Format with date: " +simpleDF.format(date));
Calendar cal = Calendar.getInstance();
System.out.println("2. Simple Date Format with calendar: " +simpleDF.format(cal.getTime()));
LocalDateTime now = LocalDateTime.now();
System.out.println("3. Date Time Format with local time: " +dateTF.format(now));
LocalDate localDate = LocalDate.now();
System.out.println("4. Date Time Format with local date: " +dateTF.ofPattern("yyy/MM/dd").format(localDate));
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
System.out.println("5. current date/time: " +timeStamp);
}
}
Output;
No comments:
Post a Comment