Make sure that SimpleFormat.format(String) continues to work for custom formats

This commit is contained in:
Reinhard Pointner 2016-02-22 04:46:37 +00:00
parent 158119a26b
commit fe49ebf36d
1 changed files with 11 additions and 1 deletions

View File

@ -5,8 +5,10 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -90,6 +92,14 @@ public class SimpleDate implements Serializable, Comparable<Object> {
return new SimpleDate(year, month, day);
}
public String format(String pattern) {
return DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH).format(this.toLocalDate());
}
public LocalDate toLocalDate() {
return LocalDate.of(year, month, day);
}
@Override
public String toString() {
return String.format("%04d-%02d-%02d", year, month, day);
@ -105,6 +115,6 @@ public class SimpleDate implements Serializable, Comparable<Object> {
return null;
}
public static final Pattern DATE_FORMAT = Pattern.compile("(\\d{4}).(\\d{1,2}).(\\d{1,2})");
public static final Pattern DATE_FORMAT = Pattern.compile("(\\d{4})\\D(\\d{1,2})\\D(\\d{1,2})");
}