DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • What Is mTLS? How To Implement It With Istio
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Five Java Books Beginners and Professionals Should Read
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices

Trending

  • What Is mTLS? How To Implement It With Istio
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Five Java Books Beginners and Professionals Should Read
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  1. DZone
  2. Coding
  3. Java
  4. Java 获取指定日期所在周的第一天

Java 获取指定日期所在周的第一天

Nile Black user avatar by
Nile Black
·
May. 22, 09 · Code Snippet
Like (0)
Save
Tweet
Share
2.07K Views

Join the DZone community and get the full member experience.

Join For Free
// 获取指定日期所在周的第一天


      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);//这里设置从周一开始,若需要根据系统时区自动获取,则采用下边的方式
      //cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());//
      System.out.println(cal.getTime());


测试结果

Wed Apr 29 10:24:45 CST 2009		Mon Apr 27 10:24:45 CST 2009
Thu Apr 30 10:24:45 CST 2009		Mon Apr 27 10:24:45 CST 2009
Fri May 01 10:24:45 CST 2009		Mon Apr 27 10:24:45 CST 2009
Sat May 02 10:24:45 CST 2009		Mon Apr 27 10:24:45 CST 2009
Sun May 03 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Mon May 04 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Tue May 05 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Wed May 06 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Thu May 07 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Fri May 08 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Sat May 09 10:24:45 CST 2009		Mon May 04 10:24:45 CST 2009
Java (programming language)

Opinions expressed by DZone contributors are their own.

Trending

  • What Is mTLS? How To Implement It With Istio
  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Five Java Books Beginners and Professionals Should Read
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: