Hi everyone,

I am trying to set my own calendar in JAVA. What I mean is, unlike the default Calendar I want to construct my own Calendar where a day will be only 13 hours for example instead of the 24 and there will be 30 days in every month.

Can anyone please guide me ?

Thank you in advance

How about something like this?

public class MyCalendar
    private int month;
    private int day;
    private int year;
    private int hour;
    private int minute;
    private int second;

    public static int NUM_SEC_IN_MINUTE = 23;
    public static int NUM_MIN_IN_HOUR = 8;
    public static int NUM_HOUR_IN_DAY = 13;
    // etc.

Seems like everything would be just like the regular calendar except for the constants.

I don't know how in depth you want to go with this, but you may be able to extend Calendar and not have to do all the work, just change some constants. I've never played around with Calendar, but often you can take an existing class and tweak it to your needs so you don't have to completely reinvent the wheel.


Calendar is an abstract class, so it's designed and built to be extended (the concrete sub-class you normally use is GregorianCalendar). You should be able to have some fun extending it for a custom calendar, although the JavaDoc doesn't have enough info to tell if you can safely change things like hours/day. It may be worth downloading the source to see how it's implemented.

This article has been dead for over six months. Start a new discussion instead.