fork download
  1. import java.time.LocalDateTime;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. String english = "Your Last Login was 2013/10/04 13:06:45 ( 0 Days, 0 Hours, 0 Minutes )";
  9. String chinese = "您上次登录是 2013/10/04 13:06:45( 0 天, 0 小时 0 分钟 )";
  10.  
  11. // Assuming the date-time string is in the format, yyyy/MM/dd HH:mm:ss
  12. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu/M/d H:m:s");
  13.  
  14. // Processing english
  15. LocalDateTime dt = LocalDateTime.parse(getDateTime(english), dtf);
  16. System.out.printf("Year: %d, Month: %d, Day: %d, Hour: %d, Minute: %d, Second: %d%n", dt.getYear(),
  17. dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute(), dt.getSecond());
  18.  
  19. // Processing chinese
  20. dt = LocalDateTime.parse(getDateTime(chinese), dtf);
  21. System.out.printf("Year: %d, Month: %d, Day: %d, Hour: %d, Minute: %d, Second: %d%n", dt.getYear(),
  22. dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute(), dt.getSecond());
  23. }
  24.  
  25. static String getDateTime(String s) {
  26. Matcher matcher = Pattern.compile("\\d{1,4}\\/\\d{1,2}\\/\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}").matcher(s);
  27. String strDateTime = "";
  28. if (matcher.find()) {
  29. strDateTime = matcher.group();
  30. }
  31. return strDateTime;
  32. }
  33. }
Success #stdin #stdout 0.15s 53124KB
stdin
Standard input is empty
stdout
Year: 2013, Month: 10, Day: 4, Hour: 13, Minute: 6, Second: 45
Year: 2013, Month: 10, Day: 4, Hour: 13, Minute: 6, Second: 45