Javaのカレンダークラス:誕生日の計算を入力します-生きた日と記念する10、000日



Calendar Class Java



package day03 import java.text.ParseException import java.text.SimpleDateFormat import java.util.Date import java.util.Scanner /** * Request to enter your own birthday in the format 1995-01-01 * After calculation, output: XXX days have been lived until today. * and how many days are there from 10,000 days. * The anniversary of 10,000 days of survival is: 2020-10-10 * @author kaixu * */ public class Test03 { public static void main(String[] args) throws ParseException { System.out.println('Please enter your birthday: (eg 1990-01-01)') Scanner scanner = new Scanner(System.in) String birStr = scanner.nextLine() SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd') Date birth = sdf.parse(birStr) //How many days have you calculated? Date now = new Date() long time = now.getTime()-birth.getTime() time = time/1000/60/60/24 System.out.println('Congratulations, you have lived together until today.'+time+'Day. Please keep it.') time = 10000-time System.out.println('There is still 10,000 days to live'+time+'day.') time = time*1000*60*60*24 now.setTime(now.getTime()+time) System.out.println('The anniversary of 10,000 days of survival is:'+sdf.format(now)) } }