diff options
author | Tom Tromey <tromey@cygnus.com> | 1999-09-24 19:12:23 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 1999-09-24 19:12:23 +0000 |
commit | 98e7ae2962ad70fed5e3d776bf6992a2a154d629 (patch) | |
tree | 1ae1fb27538f4637b0c7cebaa4d290138da435a5 /libjava/java/util/Date.java | |
parent | aaaec1142d3e7b9174ecd74fd21c6c39d696d56d (diff) | |
download | gcc-98e7ae2962ad70fed5e3d776bf6992a2a154d629.zip gcc-98e7ae2962ad70fed5e3d776bf6992a2a154d629.tar.gz gcc-98e7ae2962ad70fed5e3d776bf6992a2a154d629.tar.bz2 |
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
Diffstat (limited to 'libjava/java/util/Date.java')
-rw-r--r-- | libjava/java/util/Date.java | 29 |
1 files changed, 26 insertions, 3 deletions
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) |