Java Time Processing classic case

Source: Internet
Author: User

Tag: Lin text imp expires day new util static pack

Package day1;

Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
Import Java.util.Scanner;


/*
* Calculation of promotional dates
* Enter a build date, one shelf life days
* The promotion date is 2 weeks before the expiry of Wednesday * *
public class Test2 {
public static void Main (string[] args) throws ParseException {
Scanner read=new Scanner (system.in);
System.out.println ("Please enter production date Yyyy-mmm-dd");
String Datastr=read.nextline ();
System.out.println ("Please enter the number of days for the shelf life");
int Day=integer.parseint (Read.nextline ());
String-Date
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd");
Date Date=sdf.parse (DATASTR);
Date->calendar
Calendar calendar=calendar.getinstance ();
Calendar.settime (date);
Calendar.add (Calendar.day_of_year, day);
Calendar.add (Calendar.day_of_year,-14);
Calendar.set (Calendar.day_of_week, 4);
Calendar->date
Date=calendar.gettime ();
Datastr=sdf.format (date);
System.out.println ("Promotional date" +datastr);

}

}

Java Time Processing classic case

Related Article

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.