Asha
Asha

Reputation: 11232

How to get today as a string in Java 5?

For example for today I want string as "Sunday". I know how to do this in Java 6:

String day = Calendar.getInstance().getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());

But this doesn't compile in Java 5. Any idea how to do this?

Upvotes: 3

Views: 181

Answers (2)

Patrick
Patrick

Reputation: 3739

switch (Calendar.getInstance ().get (Calendar.DAY_OF_WEEK)) { ... }

Upvotes: 1

extraneon
extraneon

Reputation: 23950

You could use DateFormat:

SimpleDateFormat weekdayFormat = new SimpleDateFormat("EEEE");
System.out.println(weekdayFormat.format(new Date()));

I haven't tried it but this should work.

Upvotes: 4

Related Questions