Calender Date is getting printed wrong. | Selenium Forum
M
Posted on 11/01/2016
My Date after accpeting from main function into another function and then after formatting it. Date is printed wrong.
following is my code.[code:35q2mv2d]



package actionClass;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Calender_MakeMyTrip {
static WebDriver driver;

public static void main(String[] args) throws InterruptedException,
ParseException {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS)
.pageLoadTimeout(60, TimeUnit.SECONDS);

driver.navigate().to("http://www.travelyaari.com/");
driver.findElement(By.id("departDate")).click();

/*
* WebElement getSiteDate = driver .findElement(By
* .cssSelector("a.ui-state-default.ui-state-highlight.ui-state-active"
* ));
*
* System.out.println("Site Date:- " + getSiteDate.getText());
* getSiteDate.click();
*/

selectDate("11/01/16");

driver.close();
}

public static String selectDate(String date) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("DD/MM/YYYY");
Date datetobeselected = formatter.parse(date);
Date Currentdate = new Date();
String monthYearDisplayed = driver.findElement(
By.xpath("html/body/div[4]/div[1]/div/div")).getText();

System.out.println(datetobeselected);
System.out.println(Currentdate);
System.out.println(monthYearDisplayed);
String month = new SimpleDateFormat("MMMM").format(datetobeselected);
String year = new SimpleDateFormat("YYYY").format(datetobeselected);
System.out.println(month + " --- " + year);

return null;
}
}
[/code:35q2mv2d]

M
Replied on 11/01/2016

what are you trying to do?


M
Replied on 11/01/2016

I am studing.Module no.15 -Part 3.
I am trying whatever the trainer is doing on my own.
But after parsing the string date i stored it in Date variable and when i am printing it. the Date is printed wrong.
I have pasted the complete code. Can you please give the solution. Because i have the exact same code as trainer but i am getting wrong output in console.
Thanks for reply.


M
Replied on 12/01/2016

ok use this

[quote:37p2a86v] SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");[/quote:37p2a86v]

for more information
http://stackoverflow.com/questions/5580965/java-date-formatter