Java gets the month and day of the current time and the Monday weekend date of the current week, respectively

Source: Internet
Author: User

I used to use date to intercept, but the history of all the scenes are suitable, or the efficiency can not meet, or splicing extra trouble. It's better to be able to use Java's methods to achieve this. Because the cultural differences between China and the West sometimes in the simple way we have to add some other to calculate, who let Java is the language of the West, I also want to use the development of domestic language, but do not know this life can see. On the code:

SimpleDateFormat simdf = new SimpleDateFormat ("MM month DD day"); Calendar cal = Calendar.getinstance (); System.out.println ("Present Time:" +simdf.format (Cal.gettime ()));//Get year, month, Day System.out.println ("Year:" +cal.get (CAL) respectively. year)); System.out.println ("Month:" + (Cal.get (Cal. Month) (+1));//The foreigner put January into 0, translated into the Chinese month to add 1system.out.println ("Day:" +cal.get (CAL). DATE)); Cal.set (Cal. Day_of_week, Cal. MONDAY); String Weekhand = Simdf.format (Cal.gettime ()); System.out.println ("Current Time week 1st:" +weekhand);//cal.set (Cal. Day_of_week, Cal. SUNDAY); This does not accord with the Chinese view of time, the foreigner set last week Sunday as the beginning of a week. Cal.set (Calendar.date, Cal.get (Cal. DATE) + 6); String weeklast = Simdf.format (Cal.gettime ()); System.out.println ("The current time is on the Sunday of the day:" +weeklast);

Run output:

Current time: July 06 Year: 2017 months: 7th: 6 Current Time Week 1st period: July 03 Current time weekday Sunday: July 09

  

Java gets the month and day of the current time and the Monday weekend date of the current week, respectively

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: info-contact@alibabacloud.com 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.