I
I
igrishaev2012-09-19 03:05:23
Java
igrishaev, 2012-09-19 03:05:23

Format date?

You need to get a string like "September 2012", "December 2012" and so on from the date.
What I did: I set the Russian locale, I try to format according to the pattern "MMMM yyyy", it gives out "September 2012", i.e. in the genitive case, but in the nominative case. I don't want to deal with arrays and string concatenation.
Googling suggested that others have the opposite problem: the month is displayed in the nominative case, but they need it in the genitive. It just baffled me.
Maybe you can slip your own array of month names into the formatter?
UPD: code

Locale locale = new Locale("ru");
Locale.setDefault(locale);

SimpleDateFormat MONTH_DF = new SimpleDateFormat("MMMM yyyy");
Date date = new Date();
((TextView) view.findViewById(R.id.statements_item_date)).setText(MONTH_DF.format(date));

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
gvsmirnov, 2012-09-19
@gvsmirnov

About where the roots of your problem are already noted above: SimpleDateFormat is part of the standard library, and its behavior depends on the vendor.
But in general, working with dates in the standard library is terrible: take only the fact that SDF is not thread-safe. Use Joda Time , Luke! It is much more convenient to work with this library, it is more powerful, without wild bugs and is constantly evolving, unlike.

N
nikolawan, 2017-02-15
@nikolawan

new SimpleDateFormat("LLLL yyyy")

B
barker, 2012-09-19
@barker

Well, show me some code.

Maybe you can slip your own array of month names into the formatter?

You can:
DateFormatSymbols.setMonths -> new SimpleDateFormat("MMMM yyyy", symbols);

S
SSiarhei, 2012-09-19
@SSiarhei

ran your code - output "September 2012"
jdk 1.6.0_33

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question