java-web--11th Class Time class

Source: Internet
Author: User
Tags java web


In our study of the Java Web, the properties of entity classes often encounter time classes

The time class is also a very important class,

First, let's take a look at the time classes that are often used

Frequently used time classes are those three classes

Specific can consult the API


Our chapter is mainly to do three topics to familiarize yourself with the role of these three classes

Topic: Topic One: Calculationtoday's national Day from this year(2017-10-1) How many days are there? Topic Two: Calculationlast week, FridayThe date is? Topic Three: Calculationthe fifth day of the National Day last yearWhat's the day of the week? Solve the problem one:

Get the problem, don't feel you can't do it, or you'll lose in the beginning.

Get the problem, first analyze the problem

For example: What variables need to be used, which classes to use

First, what are those quantities?

Today from National Day

Two variables, one is today's time, one is the time of this year's National day

What classes do you need to use?

Date of time, conversion of SimpleDateFormat, calculation of the calendar

1. Definition of two variables

2. Define time for National day, convert to time format

3. Calculate today is the day of the year, the National Day is the first days of this year, subtract it out

1. Today is the first day of the year


2. National Day is the day of the week


3. Calculate the Difference


4. Draw Results

Solve problem Two:

Get the problem, first analyze the problem

Calculated on last week's Friday date

When I think of calculating dates, I think of the Calendar class

To calculate last week, one of us took a time style as a dimension

For example, years, months, days, weeks, hours, minutes, seconds

We'll divide the week into a dimension.

First count last week's date

In calculating the date of Friday of that week

1. Get today's time first

2. Calculate the week of the year

3. Last week, minus 2 weeks.

4. Minus two weeks time, on completion of last week's time,

But what we need is Friday last week.

So let's change the latitude and count the Friday of that week.

Why is 6, because Sunday is the first day of one weeks

So Friday is 6.

5. Removal time

6. Check the answers

Solve the problem three:

5 days after the national day last year is the day of the week

Analyze the problem, can't take this year's time to judge, because this year will change

So we need to subtract a year from the Calendar class,

Then set the month and the numbered to October 1,

Then add five days to get the week

1. Get today's date

2. Year minus One

3. Set the month (0月 for January, so September represents October)

4. Set the numbered

5. Add five days

6. Get the Week

7. Output results

8. Verify the Answer


Date Time Class

SimpleDateFormat: For conversion and parsing time classes

Calendar: Used to calculate time

Especially calendar, a bit difficult to master,

Need to practice and learn more about the methods and properties

java-web--11th Class Time class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.