Date Format issue.

In DateFormat class,

SHORT is completely numeric, such as 12.13.52 or 3:30pm

MEDIUM is longer, such as Jan 12, 1952

LONG is longer, such as January 12, 1952 or 3:30:32pm

FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST.

I am wondering if there is any way to display just month and year , e.g, July 2007. And according to Locale to display the string if in different languages.(which might also mean different format, e.g, year month instead of month year.)

Cheers,

[552 byte] By [lindda] at [2007-11-27 9:36:50]
# 1
Use SimpleDateFormat. By doing so you can specify the format.
floundera at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 2
Read the API for SimpleDateFormat (which is linked to from the DateFormat page under the "See Also" section, up top).
masijade.a at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 3
Thx for replying. The thing is I dont want to control it by myself. E.g, if Locale is in China, Chinese guys actually prefer to use "year month" which are also in Chinese, not numbers.So if I give it a Locale, is it going to get the corresponding local language string?Ta,
lindda at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 4
What does the API say about it? And have you tried it?Edit:I'm not a Chinese (or any other) local expert (and, AFAIK, neither is anyone else here), so I would also have to simply try it, and since it is your situation, I would say for you to try it first.
masijade.a at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 5
You could write your own class the creates a Locale specific SimpleDateFormat object.
floundera at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 6

yes, i tried a couple of ways.

If I use constructor SimpleDateFormat(String pattern, Locale locale) , it will stay same.

If I use DateFormat.getDateInstance(DateFormat.LONG), since DateFormat only has a few default modes, I cannt really get "year month", although it does come up with the local language.

lindda at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 7
To flounder :Sounds like an idea.
lindda at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...
# 8

> yes, i tried a couple of ways.

>

> If I use constructor SimpleDateFormat(String pattern,

> Locale locale) , it will stay same.

>

>

> If I use DateFormat.getDateInstance(DateFormat.LONG),

> since DateFormat only has a few default modes, I

> cannt really get "year month", although it does come

> up with the local language.

Well, then, there was your answer. ;-)

If you know that the Chinese locale should be year month, but the Locale provided by Java is not doing that, you may wish to put in an RFE (Request For Enhancement), or a report a Bug, and see if you can get Sun to change it (although they will probably simply claim that it is not a bug, and that you are mistaken (which could also be the case)).

Edit:

Although, I believe in most cases, that the Locale class depends on the locale info provided by the OS, in which case Sun is not at fault (except for Solaris).

masijade.a at 2007-7-12 23:06:45 > top of Java-index,Java Essentials,Java Programming...