Use a simple Swing Calendar Bean to learn Calendar class (1) Calendar overview

zhaozj2021-02-16  57

In the date formatted, I used to describe how to customize the date format text from a java.util.date date class. Today we will enter a real problem, learn about the real date object Calendar class in Java, and build a practical SWING calendar bean during the analysis process.

I have searched some practical SWING calendars online, but their implementation is more complicated. Here we will use only one class and standard Swing components to implement this calendar, so that this bean can be easily reused.

First, what is Calendar?

The Calendar class is a calendar tool class provided by the Java Standard Library, which is an abstract class. Among it defines a number of useful methods, the most useful is to freely transform the date and time of the SET method, and get the GET method output from the custom date. Because Calendar is an abstract class, it can't create an instance using the new method, it needs to be used: Calendar Calendar = Calendar.getInstance ();

In the Calendar class, the date is divided into the year, month, day, time, minute, second, microseconds, west of eight parts, each portion has one or more domains (Field), in the use of SET or GET methods It is actually accessed through these domains. Every domain is a static integer constant, they are:

area

Representative meaning

AM_PM

AM / afternoon logo

Date

Complete date logo

Day_of_month

The first few days this month

Day_of_week

Day of the week

Day_of_week_in_month

(Not understood)

Day_of_year

The first few days of this year

DST_OFFSET

Time zone offset

ERA

BC mark

Hour

Hours (12 hours, division on the afternoon)

Hour_of_day

Hours (24-hour system, regardless of afternoon)

MilliseCond

Microseconds

Minute

minute

Month

month

SECOND

second

WEEK_OF_MONTH

The first week of this month

WEEK_OF_YEAR

The first week of this year

Year

years

ZONE_OFFSET

Microsecondal time offset relative to the GMT time zone

In addition to the functionality of accessing domain values ​​via set and get methods, Calendar provides some useful methods:

method

parameter

significance

getActualMaximum

Int Field

Get the maximum value of the current time specified domain value

getActualMinimumum

Equally

Get the minimum value of the current time specified domain value

GetFirstdayofweek

air

Get the first day of the current time zone for a week,

Such as: Sunday is the first day of a week;

It is Monday in France.

GetTime

air

Return a java.util.date date object

GetTimeInmillis

air

Returns the cumulative value of the current time, just like

GetTime method in java.util.date

GetTimezone

air

Returns the current time zone

Isset

Int Field

Set whether the domain can be rewritten

SetFirstdayofweek

Int Value

Set the first day of the current time zone for a week,

Such as: Sunday is the first day of a week;

It is Monday in France.

Settime

Date Date

Reset a java.util.date for the current calendar

Date object as the current time

SetTimeInmillis

air

Set a microsecond accumulated value for a time as the current time

Settimezone

Timezone Value

Set the current time zone

转载请注明原文地址:https://www.9cbs.com/read-22269.html

New Post(0)