From 98e7ae2962ad70fed5e3d776bf6992a2a154d629 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 24 Sep 1999 19:12:23 +0000 Subject: re GNATS java.util/47 (Date.toString() returns embedded newline) Fix for PR java.util/47: * configure, include/config.h: Rebuilt. * configure.in: Don't look for ctime or ctime_r. * Makefile.in: Rebuilt. * Makefile.am (nat_source_files): Don't mention natDate.cc. * java/util/natDate.cc: Removed. * java/util/TimeZone.java (tzIDs, rawOffsets, timeZones): New static fields. (getAvailableIDs): Rewrote. (getTimeZone): Rewrote. * java/util/Date.java (toGMTString): New method. (toLocaleString): New method. (toString): Rewrote. From-SVN: r29656 --- libjava/java/util/Date.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'libjava/java/util/Date.java') diff --git a/libjava/java/util/Date.java b/libjava/java/util/Date.java index 3d23780..a5258a0 100644 --- a/libjava/java/util/Date.java +++ b/libjava/java/util/Date.java @@ -445,10 +445,33 @@ public class Date implements java.io.Serializable, Cloneable + cal.get(Calendar.DST_OFFSET)/(60*1000)); } - public native String toString (); + public String toString () + { + // This is slow, but does it matter? There is no particularly + // fast way to do it, because we need the timezone offset, which + // we don't store. Unix ctime() doesn't provide this information. + SimpleDateFormat fmt = new SimpleDateFormat ("E MMM dd HH:mm:ss z yyyy", + Locale.US); + fmt.setTimeZone(TimeZone.getDefault()); + return fmt.format(this); + } - // TODO: toLocaleString - // TODO: toGMTString + public String toGMTString () + { + // This method is deprecated. We don't care if it is very slow. + SimpleDateFormat fmt = new SimpleDateFormat ("d MMM yyyy HH:mm:ss 'GMT'", + Locale.US); + fmt.setTimeZone(TimeZone.zoneGMT); + return fmt.format(this); + } + + public String toLocaleString () + { + // This method is deprecated. We don't care if it is very slow. + DateFormat fmt = DateFormat.getDateTimeInstance(); + fmt.setTimeZone(TimeZone.getDefault()); + return fmt.format(this); + } public static long UTC (int year, int month, int date, int hours, int minutes, int seconds) -- cgit v1.1