Working with the Dates :
It is very common to work with dates in part of our automation testing,Generally we come across the following requirements:
- Getting the current System date in various formats
- Getting the previous dates in various formats
- Getting the future dates in various formats
This post will make easier the things.
Steps to follow:
- Download the jar file from https://drive.google.com/file/d/0B9ZTXXKTZAYVUGZ5d0loWUNhMlk/edit?usp=sharing
- Add the ‘testUtils.jar’ (I will provide the .Jar file ) file to your project class path, Import the following class in your Test.java file
-
Import com.webdriver.framework.*; (If it’s not already imported)
Hello,
ReplyDeleteWhile executing the below code, i am getting wrong month. Day and Year is correct. Could you please check ?
import org.testng.annotations.Test;
import com.webdriver.framework.TestUtils;
public class s022_workingWithDates {
@Test
public void tests022_workingWithDates() {
TestUtils util = new TestUtils();
System.out.println(util.computedDateFromTodayDate("dd/mm/yyyy",0));
System.out.println(util.computedDateFromTodayDate("mm/dd/yyyy",0));
System.out.println(util.computedDateFromTodayDate("yyyy/mm/dd",0));
System.out.println("\n");
System.out.println(util.computedDateFromTodayDate("dd/mm/yyyy",1));
System.out.println(util.computedDateFromTodayDate("mm/dd/yyyy",1));
System.out.println(util.computedDateFromTodayDate("yyyy/mm/dd",1));
System.out.println("\n");
System.out.println(util.computedDateFromTodayDate("dd/mm/yyyy",-1));
System.out.println(util.computedDateFromTodayDate("mm/dd/yyyy",-1));
System.out.println(util.computedDateFromTodayDate("yyyy/mm/dd",-1));
}
}
Please try with capital MM, Please find the corrected code:
ReplyDeleteSystem.out.println(util.computedDateFromTodayDate("dd/MM/yyyy",0));
System.out.println(util.computedDateFromTodayDate("MM/dd/yyyy",0));
System.out.println(util.computedDateFromTodayDate("yyyy/MM/dd",0));
System.out.println("\n");
System.out.println(util.computedDateFromTodayDate("dd/MM/yyyy",1));
System.out.println(util.computedDateFromTodayDate("MM/dd/yyyy",1));
System.out.println(util.computedDateFromTodayDate("yyyy/MM/dd",1));
System.out.println("\n");
System.out.println(util.computedDateFromTodayDate("dd/MM/yyyy",-1));
System.out.println(util.computedDateFromTodayDate("MM/dd/yyyy",-1));
System.out.println(util.computedDateFromTodayDate("yyyy/MM/dd",-1));
OUTPUT for the above code is :
ReplyDelete20/02/2014
02/20/2014
2014/02/20
21/02/2014
02/21/2014
2014/02/21
19/02/2014
02/19/2014
2014/02/19