A nice cross-locale same-width DateTime.toString()? (original) (raw)

Weijun Wang weijun.wang at oracle.com
Wed Apr 25 10:05:38 UTC 2012


Hi All

We have a command line tool that needs to print out date/time in a table. The current Date.toString() always has the same width and it's beautiful:

    76 Tue Nov 10 08:57:54 CST 2009 bin/vbin/go
  1149 Sun Apr 08 16:03:20 CST 2012 bin/vbin/netbeans
   170 Fri Nov 20 16:47:42 CST 2009 bin/vbin/syncdown
   671 Wed Feb 08 20:11:22 CST 2012 bin/vbin/ssh.desktop
   187 Fri Nov 20 16:47:34 CST 2009 bin/vbin/syncsf

However, both the DOW and MON are English and might make non-English users unhappy.

On the other hand, DateFormat.getDateTimeInstance() knows about locale but the output is not the same width.

    76 Nov 10, 2009 8:57:54 AM bin/vbin/go
  1149 Apr 8, 2012 4:03:20 PM bin/vbin/netbeans
   170 Nov 20, 2009 4:47:42 PM bin/vbin/syncdown
   671 Feb 8, 2012 8:11:22 PM bin/vbin/ssh.desktop
   187 Nov 20, 2009 4:47:34 PM bin/vbin/syncsf

or when -Duser.language=fr

    76 10 nov. 2009 08:57:54 bin/vbin/go
  1149 8 avr. 2012 16:03:20 bin/vbin/netbeans
   170 20 nov. 2009 16:47:42 bin/vbin/syncdown
   671 8 févr. 2012 20:11:22 bin/vbin/ssh.desktop
   187 20 nov. 2009 16:47:34 bin/vbin/syncsf

Is there a nice way to make the output same width and locale aware?

I can wait for JDK 8.

Thanks Max



More information about the core-libs-dev mailing list