Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. String DATE_FORMAT = "yyyyMMdd";
  2. try {
  3. DateFormat dfyyyyMMdd = new SimpleDateFormat(DATE_FORMAT);
  4. dfyyyyMMdd.setLenient(false);
  5. Date formattedDate;
  6. formattedDate = dfyyyyMMdd.parse(aValue);
  7. console.debug(String.format("%s = %s","formattedDate",formattedDate));
  8. } catch (ParseException e) {
  9. // Not a date
  10. }
  11.  
  12. ParsePosition pos = new ParsePosition(0);
  13. dfyyyyMMdd.parse(aValue, pos);
  14. if (pos.getIndex() != aValue.length()) {
  15. // there's garbage at the end
  16. }
  17.  
  18. public Date parse(String source)
  19. throws ParseException
  20.  
  21. Parses text from the beginning of the given string to produce a date.
  22. The method may not use the entire text of the given string.
  23.  
  24. yyyyMMdd(followed by anything)
  25.  
  26. "10000514blabla" --> Tue May 14 00:00:00 EST 1000
  27. "100 112" --> Sun Jan 12 00:00:00 EST 100
  28. "1 112xyz" --> Wed Jan 12 00:00:00 EST 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement