利用Date类计算生活时间
生活随笔
收集整理的這篇文章主要介紹了
利用Date类计算生活时间
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天學(xué)習(xí)到了Date類還有其他一些常用類!
這里就簡(jiǎn)單使用Date及其一些方法計(jì)算生活時(shí)間。
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner;public class DateInput {public static void main(String[] args) throws ParseException {Scanner scanner = new Scanner(System.in);// System.out.print("請(qǐng)輸入出生年份(xxxx):"); // String next1 = scanner.next(); // System.out.print("請(qǐng)輸入出生月份(xx):"); // String next2 = scanner.next(); // System.out.print("請(qǐng)輸入當(dāng)月號(hào)數(shù)(xx):"); // String next3 = scanner.next(); // String time=next1+"年"+next2+"月"+next3+"日"; System.out.print("請(qǐng)輸入出生年月日(xxxx年xx月xx日):");String time=scanner.next();SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");Date date = new Date();Date s=format.parse(time);long tm=date.getTime()-s.getTime();System.out.println("您已出生"+tm/1000/60/60/24+"天!"+"\n約"+tm/1000/60/60/24/365+"年!");} }?
轉(zhuǎn)載于:https://www.cnblogs.com/YLTzxzy/p/10895751.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的利用Date类计算生活时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pugixml解析Word
- 下一篇: 美国地名大全(美国城市名称英文 中文)