search
HomeJavaJavaBasejava get week

java get week

Nov 18, 2019 pm 02:59 PM
javawhich week

java get week

java gets the week

1. First create a getWeek function that receives a Date type parameter;

2. Then create a GregorianCalendar instance within the function;

3. Then set the time of the GregorianCalendar instance as the received parameter;

4. Finally, use get Just get the week number.

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class GetWeek {
    /** * @param args */
    public static void main(String[] args) {
        System.out.println(getWeek(new Date()));
    }
    public static int getWeek(Date date) {
        GregorianCalendar g = new GregorianCalendar();
        g.setTime(date);
        return g.get(Calendar.WEEK_OF_YEAR); //获得周数 
    } 
}

Supplement:

The Calendar class implements the Gregorian calendar, and GregorianCalendar is a specific implementation of the Calendar class.

Calendar’s getInstance() method returns a GregorianCalendar object initialized by default with the current locale and time zone.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of java get week. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.