%@ page language="java" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
Calendar
| Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
Sun |
<%
// Calendar data
Map bookings = new HashMap<>();
bookings.put(4, "Event 1");
bookings.put(10, "Event 2");
bookings.put(21, "Event 3");
// Get the current date
LocalDate currentDate = LocalDate.now();
// Get the first day of the month
LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1);
// Get the number of days in the month
int daysInMonth = currentDate.lengthOfMonth();
// Calculate the offset for the first day
int offset = firstDayOfMonth.getDayOfWeek().getValue() - 1;
// Start the calendar table
for (int i = 0; i < 6; i++) {
out.println("");
for (int j = 0; j < 7; j++) {
int day = i * 7 + j - offset + 1;
if (day >= 1 && day <= daysInMonth) {
String event = bookings.get(day);
String cssClass = j >= 5 ? "weekend" : "";
out.println("");
out.println(day);
if (event != null) {
out.println(" ");
out.println(event);
}
out.println(" | ");
} else {
out.println(" | ");
}
}
out.println("
");
}
%>