Selenium-java-获取当前时间

时间:2021-10-25 20:55:45

1 获取当前时间 时分秒

        // 获取当前时分秒
Calendar now = Calendar.getInstance();
int is = now.get(Calendar.HOUR_OF_DAY);
int isf = now.get(Calendar.MINUTE);
int iss = now.get(Calendar.SECOND);

2 获取当前年月日

        // 获取当前年份、月份、日期
Calendar cale = null;
cale = Calendar.getInstance();
int year = cale.get(Calendar.YEAR);
int month = cale.get(Calendar.MONTH) + 1;
int day = cale.get(Calendar.DATE);
        System.out.println("Year年: " + year);  
        System.out.println("Month月: " + month);  
        System.out.println("Day日: " + day);