Calendar toString() in Java

toString(): This method is available in java.util.Calendar class of Java.

Syntax:

String java.util.Calendar.toString()

This method returns a string representation of this calendar.

Parameters: NA

Returns: a string representation of this calendar.

Exceptions: NA

Approach

Java

import java.util.Calendar;

public class CalendartoString {
    public static void main(String[] args) {

        // create a calendar
        Calendar calendar = Calendar.getInstance();

        System.out.println(calendar.toString());

    }
}

Output:

java.util.GregorianCalendar[time=1642960815367,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2022,MONTH=0,WEEK_OF_YEAR=5,WEEK_OF_MONTH=5,DAY_OF_MONTH=23,DAY_OF_YEAR=23,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=30,SECOND=15,MILLISECOND=367,ZONE_OFFSET=19800000,DST_OFFSET=0]


No comments:

Post a Comment