寫一程式可輸入生日(年月日)後,計算到今天為止的總天數為多少天?(不考慮閏年與閏月的問題)
import java.lang.*; import java.util.*; public class diffdate { public static void main(String[] args) throws Exception{ java.text.DateFormat df = java.text.DateFormat.getDateInstance(); java.util.Date td1 = (new java.text.SimpleDateFormat( "dd/MM/yyyy ")).parse( "01/03/2007 "); long lBeginTime = td1.getTime() ; java.util.Date td2 = (new java.text.SimpleDateFormat( "dd/MM/yyyy ")).parse( "19/04/2007 "); long lEndTime = td2.getTime() ; int iDay = (int)((lEndTime-lBeginTime)/86400000); System.out.print("day:"+iDay); } }
全站熱搜
留言列表