1

I have a scenario where I get the date value from the xml and the date value from the website. I am able to retrieve the results, But now I need to compare the format of the retrieved results whether it is in 'MM YYYY' format or not ? How can i do that ? i have to check the format in String manner ie for e.g Apr 2010 but not 04 2010

Please can anyone of you help me ??

Rhino 0419
  • 29
  • 2
  • By the way, check out the [`YearMonth`](http://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html) class of the java.time framework built into Java 8 and later. – Basil Bourque Mar 17 '16 at 10:49

2 Answers2

1
public class SimpleDate {

  public static void main(String[] args) {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
    String strDate = sdf.format(date);   
    sdf = new SimpleDateFormat("MMM/yyyy");
    strDate = sdf.format(date);
    System.out.println(strDate);

  }
}
Anand Kumar
  • 389
  • 1
  • 7
  • 21
0

You can use a regular expresson, like this (Jan|Feb|Mar...) d{4}

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275