fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String toParse = "20140102";
  14. Pattern pattern = Pattern.compile("(\\d{4})(\\d{2})(\\d{2})");
  15. Matcher matcher = pattern.matcher(toParse);
  16. if (matcher.find()) {
  17. int year = Integer.parseInt(matcher.group(1));
  18. int month = Integer.parseInt(matcher.group(2));
  19. int day = Integer.parseInt(matcher.group(3));
  20.  
  21. System.out.println(new Date(year - 1900, month - 1, day));
  22. }
  23. }
  24. }
Success #stdin #stdout 0.11s 321088KB
stdin
Standard input is empty
stdout
Thu Jan 02 00:00:00 GMT 2014