Rocky
Rocky

Reputation: 527

formatting a date in an array

I have a 2-dimensional array which retrieves a date from a database. I want the value to be formatted in days only, "12","13". How can I achieve this this?

This is my code:

String headerQuery = "SELECT DISTINCT attendance FROM Attendance;";
            Object[][] headerQueryResult = connectToDB(headerQuery);

            for(int x = 0; x < headerQueryResult.length; x++){
                for(int y=0; y < headerQueryResult[x].length; y++){
                    System.out.print(headerQueryResult[x][y]+" ");

                }
                System.out.println("---");
            }

Upvotes: 0

Views: 35

Answers (2)

Macrosoft-Dev
Macrosoft-Dev

Reputation: 2185

very simple

SimpleDateFormat sdf = new SimpleDateFormat("dd");

int day = Integer.parseInt(sdf.format( dateObject ))

Upvotes: 0

Evan Knowles
Evan Knowles

Reputation: 7501

Try this, assuming you're getting an array of dates back.

SimpleDateFormat format = new SimpleDateFormat("dd");

<loop>
System.out.print(format.format((Date) headerQueryResult[x]);

Upvotes: 3

Related Questions