Module 20 -> CalenderControl | Selenium Forum
M
Posted on 09/10/2016
Hi Ashish,
I try to print dd/MM/yyyy of the string date using [b:1wm44erd]SimpleDateFormat[/b:1wm44erd] and its working fine but when i change the date format i.e.[b:1wm44erd] SimpleDateFormat sdf = new SimpleDateFormat("MM");[/b:1wm44erd] and print that it display wrong input, same case happen if i want to print only year. So please tell me where i am wrong.
[b:1wm44erd]Code and Screen shot attached :- [/b:1wm44erd]

package Zoho.TestCases;

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

import org.testng.annotations.Test;

public class calenderRoughWork {


@Test
public void calenderFunctionality() throws ParseException{

//Date d = new Date();
//System.out.println(d);

String date = "22/12/2000";
SimpleDateFormat sdf = new SimpleDateFormat("MM");
Date d1 = sdf.parse(date);
System.out.println("The selecting date is -- > " + sdf.format(d1));


/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
System.out.println(sdf.format(d));*/

}

}

M
Replied on 10/10/2016

in line 19th you tell java ho date is formatted. after that you can try and print date and month separately.


M
Replied on 10/10/2016

Yes but problem is that month should be display 12 because my string date = "22/12/2000"so why it is displaying 10 even i am not write month as 10 ??


M
Replied on 10/10/2016

[quote="SamSelenium":t3eevv8n]Yes but problem is that month should be display 12 because my string date = "22/12/2000"so why it is displaying 10 even i am not write month as 10 ??[/quote:t3eevv8n]


it is just giving a random number.

use this to get a month

http://stackoverflow.com/questions/9474121/i-want-to-get-year-month-day-etc-from-java-date-to-compare-with-gregorian-calen