I am using swing framework and applets.
If I take locale asen_US
, the time shows in AM and PM.
If I take Locale as ms_MY
, the time shows in Pagi and patang.
How can I show time in AM and PM when using locale ms_MY
?
Please help me
I guess you display the time using a DateFormat
object. I even suppose you obtain your instance by calling the DateFormat.getTimeInstance()
method. What you have to know is that a DateFormat instance, obtained through the various get*Instance static methods, is tied to a given Locale. As a consequence, if you want to have AM or PM displayed, you'll have to use the getTimeInstance(int style, Locale aLocale)
version with Locale.en_US.
But be warned ! By using this method, your date will be displayed in english, as a consequence day names will be english ones. Is it really what you want ? I don't know, anyway that's what you'll get.
You can have better precision in output format by using SimpleDateFormat
.
EDIT updated informations on SimpleDateFormat.
Contrary to what I said, it is possible to have AM and PM associated to non-english hour display. However, it is not immediate, as three of the four constructors of SimpleDateFormat use Locale obejct to get their infos. The only way to mix various languages informations is to use the public SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols)
constructor, which will allow you to define your own DateFormatSymbols
instance. Constructing this object is left as an exercise.
The other three constructors use either the default Locale object or a given Locale
object (of which, obviously, only the DateFormatSymbols
will be used)
精彩评论