Enter a date to calculate how many days apart from the current system date (get the system time, get the date and date, and format the SimpleDateFormat; Enter dates for similar operations)

Source: Internet
Author: User

Package com.fuxi.test.date;
/**
* Enter a date to calculate how many days apart from the current system date (get the system time, get the date and date, and format the SimpleDateFormat; Enter dates for similar operations)
*/
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;

public class Nowtoday {

public static void Main (string[] args) {
SimpleDateFormat Nowtime,inputtime;
BufferedReader BR;
Calendar cal= calendar.getinstance ();
String year =string.valueof (Cal.get (calendar.year)),
month = string.valueof (Cal.get (calendar.month) +1),
Day = string.valueof (Cal.get (calendar.day_of_month));
Nowtime =new SimpleDateFormat ("YyyyMMdd");
try {
String now = Year+month+day;
Date nowdate = Nowtime.parse (now);
System.out.println ("Now the date is:" +now);
System.out.println ("Please enter a date, will calculate your output date and now how many days apart");

br = new BufferedReader (new InputStreamReader (system.in));
String input = Br.readline ();
Inputtime = new SimpleDateFormat ("YyyyMMdd");
Date inputdate = inputtime.parse (input);
Long seconds = Inputdate.gettime ()-nowdate.gettime ();
int k = (int) (seconds/(1000*60*60*24));
System.out.println (k);

catch (ParseException e) {
TODO auto-generated Catch block
E.printstacktrace ();
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}



}
}

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.