File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "date format" Watch "date format" New topic
Author

date format

naga raaju
Greenhorn

Joined: Mar 14, 2008
Posts: 29
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

Joined: Oct 27, 2005
Posts: 19718
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
naga raaju
Greenhorn

Joined: Mar 14, 2008
Posts: 29
sorry not working that code
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date format