I have written a Java file Handling program which fetches the date and days from an excel file where no entry has been made.
The excel file stores the attendance records for some people. and if there has been no entry for a particular day then the program should check if the day was a weekend. If it is not a weekend then the porgram should output the name and the day and date.
However the current format of the output is not as I want it to be :
No entry found for Shiv on Wed Jul 27 00:00:00 IST 2022
No entry found for Shiv on Thu Jul 28 00:00:00 IST 2022
No entry found for Shiv on Fri Jul 29 00:00:00 IST 2022
No entry found for Shiv on Mon Aug 01 00:00:00 IST 2022
No entry found for Shiv on Wed Aug 03 00:00:00 IST 2022
No entry found for Shiv on Thu Aug 04 00:00:00 IST 2022
I want the output date to be in the style 01 August 2022, Monday
How do I achieve that?
Following is the code
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Calendar;
import java.text.DateFormat;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelReader {
public static void main(String [] args) {
try {
File file=new File("./data/details.xlsx");
FileInputStream fis= new FileInputStream(file);
XSSFWorkbook wb=new XSSFWorkbook(fis);
System.out.println("Enter the sheet you want to search in: ");
Scanner sc= new Scanner(System.in);
int n= sc.nextInt();
XSSFSheet sheet=wb.getSheetAt(n-1);
Iterator<Row> itr=sheet.iterator();
while(itr.hasNext()) {
Row row=itr.next();
Iterator<Cell> cellIterator=row.cellIterator();
while(cellIterator.hasNext()) {
Cell cell=cellIterator.next();
Cell name_cell=row.getCell(0);
String name=name_cell.getStringCellValue();
if (cell.getRowIndex()!=0 && cell.getStringCellValue().equals("")&& cell.getColumnIndex()!=0){
int idate=cell.getColumnIndex();
Row first_row=sheet.getRow(0);
Cell date_cell=first_row.getCell(idate);
Date sdate=date_cell.getDateCellValue();
if (ExcelReader.DayCheck(sdate)){
System.out.println("No entry found for "+name+" on "+sdate);
}
}
}
}
System.out.println("");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static boolean DayCheck(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int day = cal.get(Calendar.DAY_OF_WEEK);
return (day != Calendar.SATURDAY && day != Calendar.SUNDAY);
}
}
This question is not like the other questions where I simply need to change the format of date to dd-mm-yyyy I need to take the date containing the day date month time and locale info to extract the date in the format dd-mm-yyyy, Day