Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get today as a string in Java 5?

Tags:

java

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?

like image 497
Asha Avatar asked Mar 21 '26 14:03

Asha


2 Answers

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.

like image 97
extraneon Avatar answered Mar 24 '26 03:03

extraneon


switch (Calendar.getInstance ().get (Calendar.DAY_OF_WEEK)) { ... }
like image 28
Patrick Avatar answered Mar 24 '26 04:03

Patrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!