How to get Month, Day and Year in Selenium Java WebDriver?

How to get Month, Day and Year in Selenium Java WebDriver?

In Selenium Java WebDriver, we can make use of GregorianCalendar(), Calendar.DAY_OF_MONTH, Calendar.MONTH, Calendar.YEAR, Calendar.SECOND,  Calendar.MINUTE and Calendar.HOUR to get Month, Day, Year, Second, Minute and Hour.

Sample Code:

int day, month, year;
int secnd, minute, hour;
GregorianCalendar date = new GregorianCalendar();

day = date.get( 
    Calendar.DAY_OF_MONTH
);
month = date.get( 
    Calendar.MONTH
);
year = date.get( 
    Calendar.YEAR
);

secnd = date.get( 
    Calendar.SECOND
);
minute = date.get( 
    Calendar.MINUTE
);
hour = date.get( 
    Calendar.HOUR
);

String todayDate = String.valueOf( month ) + 
    '/' + String.valueOf( day ) + 
    '/' + String.valueOf( year );

Leave a Reply