From a7356729e855167ec178d457bf49ac7f1d90f758 Mon Sep 17 00:00:00 2001 From: tromey Date: Thu, 24 Jul 2003 15:43:04 +0000 Subject: =?UTF-8?q?2003-07-24=20=20H.=20V=EF=BF=BDis=EF=BF=BDnen=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * java/text/SimpleDateFormat.java (format) [YEAR_FIELD]: Zero pad unless field size is 2. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69744 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/text/SimpleDateFormat.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'libjava/java/text/SimpleDateFormat.java') diff --git a/libjava/java/text/SimpleDateFormat.java b/libjava/java/text/SimpleDateFormat.java index 67523e1628d..b43c6cd86d4 100644 --- a/libjava/java/text/SimpleDateFormat.java +++ b/libjava/java/text/SimpleDateFormat.java @@ -430,11 +430,15 @@ public class SimpleDateFormat extends DateFormat buffer.append(formatData.eras[calendar.get(Calendar.ERA)]); break; case YEAR_FIELD: - temp = String.valueOf(calendar.get(Calendar.YEAR)); - if (p.size < 4) - buffer.append(temp.substring(temp.length()-2)); + // If we have two digits, then we truncate. Otherwise, we + // use the size of the pattern, and zero pad. + if (p.size == 2) + { + temp = String.valueOf(calendar.get(Calendar.YEAR)); + buffer.append(temp.substring(temp.length() - 2)); + } else - buffer.append(temp); + withLeadingZeros(calendar.get(Calendar.YEAR), p.size, buffer); break; case MONTH_FIELD: if (p.size < 3) -- cgit v1.2.1