大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
结果:
创新互联公司自2013年创立以来,先为襄城等服务建站,襄城等地企业,进行企业商务咨询服务。为襄城企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
有不清楚的地方可以最加问题我看到了会回答,或者是还要加什么功能也可以跟我说
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
/*
* 控制台输入生日,计算到今天为止进过了多少天
* 输入生日的格式:yyyy-MM-dd
*/
public class WorkDemo {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Scanner sc = new Scanner(System.in);
System.out.print("请输入你的生日, 输入格式为:yyyy-MM-dd");
String birthday = sc.nextLine();
Date birDate = sdf.parse(birthday);
Date now = new Date();
long time = now .getTime() - birDate.getTime();
long day = time/1000/60/60/24;
System.out.println("到今天经历了:"+day+"天");
}
}
import java.text.SimpleDateFormat;
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
str-你的生日
import java.util.Scanner;
import java.util.Calendar;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Calendar time =Calendar.getInstance();
Scanner scan=new Scanner(System.in);
int Y,M,D;
System.out.println("年:");
Y=scan.nextInt();
System.out.println("月:");
M=scan.nextInt();
System.out.println("日:");
D=scan.nextInt();
time.set(Y, M-1, D);
int Day=time.get(Calendar.DAY_OF_WEEK);
System.out.println("星期"+(Day-1));
}
}
注意,,这里每周是从星期天算起的,,,所以要减1
classBirth{privateStringbirth;privateStringsname;privateStringinterest;privateStringbook;privateStringfilm;publicvoidsetBirth(Stringbirth){this.birth=birth;}publicvoidsetName(Stringsname){this.sname=sname;}publicvoidsetInterest(Stringinterest){this.interest=interest;}publicvoidsetBook(Stringbook){this.book=book;}publicvoidsetFilm(Stringfilm){this.film=film;}publicStringgetBirth(){returnbirth;}publicStringgetName(){returnsname;}publicStringgetInterest(){returninterest;}publicStringgetBook(){returnbook;}publicStringgetFilm(){returnfilm;}publicvoidoutPut(){System.out.println("YourNameis:"+this.getName());System.out.println("YourBirthis:"+this.getBirth());System.out.println("YourInterestis:"+this.getInterest());System.out.println("YourBookis:"+this.getBook());System.out.println("Yourfilmis:"+this.getFilm());}}publicclassTestBirth{publicstaticvoidmain(String[]args){Birthbr=newBirth();br.setName("xuwenpeng");br.setBirth("1987/03/04");br.setInterest("basketball");br.setFilm("aidefengxiang");br.setBook("java");br.outPut();}}Result:YourNameis:xuwenpengYourBirthis:1987/03/04YourInterestis:basketballYourBookis:javaYourfilmis:aidefengxiang
获取系统时间:
import java.util.*;
import java.text.*;
public class TestDate {
public static void main(String[] args) {
Calendar ca = Calendar.getInstance();
int year = ca.get(Calendar.YEAR);//获取年份
int month=ca.get(Calendar.MONTH);//获取月份
int day=ca.get(Calendar.DATE);//获取日
int minute=ca.get(Calendar.MINUTE);//分
int hour=ca.get(Calendar.HOUR);//小时
int second=ca.get(Calendar.SECOND);//秒
int WeekOfYear = ca.get(Calendar.DAY_OF_WEEK);
}
用系统时间跟生日比较就行了