top of page

Dates and calendar

Crate clase for Date 

 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

 

public class calender {

    private Calendar c = Calendar.getInstance();
    

    // create date ftom string
    public Date genrate_date (int day,int month, int year) throws Exception{
        String gdate;
        gdate = day + "/" + month + "/" + year;
        SimpleDateFormat format1=new SimpleDateFormat("dd/MM/yyyy");
        Date dt=format1.parse(gdate);
        return dt;
    }


     // retrive the day number in the week - Ex. -  sunday will be 1
    public int dayOfWeek (Date date){
        c.setTime(date);
        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
        return dayOfWeek;    
    }

   // Retrieve the Month number
   public int month_number(String month,String format) throws Exception{
         Date date = new SimpleDateFormat(format).parse(month);
         Calendar cal = Calendar.getInstance();
         cal.setTime(date);
       return (cal.get(Calendar.MONTH));
   }


     // retrive the week number in the month - Ex. -  the second week will be 2
   public int weekInMonth(Date date){
       c.setTime(date);
        int weekInMonth =c.get(Calendar.WEEK_OF_MONTH);
       return weekInMonth;
   }


    // retrive the date in faw days - Ex. -  input (1/1/2017 , 5 ) will be 6/1/2017
   public String dateInFewDays(int numberDays, Date date ) {
       SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
       c.setTime(date);
       c.add(Calendar.DATE, numberDays);
       sdf.format(c.getTime());
       return sdf.format(c.getTime());
   }
    

}

Selenium selection Date from calendar 

Selenium - izselenium aoutomation tool

054-8059589

  • White Facebook Icon
  • White Twitter Icon
  • White Google+ Icon
  • White YouTube Icon

© 2017 by izselenium

bottom of page