Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date format

 
naga raaju
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i gave the date format like this

2008-05-02 i need the day of week means 2may day is "friday" so its order is 6

how to get like this in java.

i use calender.get(Calendar.DAY_OF_WEEK); but not working.

any ide

bye
naga
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it not working? How have you created the Calendar object you're getting the weekday from?

Also, don't assume weekdays are 1-based or 0-based. Instead, use the constants to convert:

Since Calendar.SUNDAY is guaranteed to be the lowest of these values (by the API), subtracting it from the weekday will guarantee a 0-based weekday.

It's even better to just always compare with the constants like Calendar.FRIDAY. The only reason you'd want to use the above approach is when using the day index as array indexes, where you want absolute guarantees that it is 0-based.

Please be careful though when using DateFormatSymbols. The arrays it returns will only work with the constants; there are often empty values at index 0 if the constants start at 1.
 
naga raaju
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry not working that code
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by naga raaju:
...
i use calender.get(Calendar.DAY_OF_WEEK); but not working...
calender should have been instantiated in this way.It's an abstract class.


This will give you 6 as output.
[ May 02, 2008: Message edited by: Vishal Pandya ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic