Java取得日期时间的代码

使用SimpleDateFormat 来获取时间
        SimpleDateFormat dateFormat = new  SimpleDateFormat( " yyyyMMddHHmmss " );
        String date
= dateFormat.format( new  Date()); 
        
return  Long.parseLong(date);



使用Canlendar 类来取得时间

        Calendar time = Calendar.getInstance(); 
        time.setTime(
new  Date( 1165991528156L ));
        
        System.out.println(
" Year: " + time.get(Calendar.YEAR));
        System.out.println(
" MONTH: " + time.get(Calendar.MONTH));
        System.out.println(
" DATE: " + time.get(Calendar.DATE));
        System.out.println(
" HOUR: " + time.get(Calendar.HOUR));
        System.out.println(
" MINUTE: " + time.get(Calendar.MINUTE));
        System.out.println(
" SECOND: " + time.get(Calendar.SECOND));

你可能感兴趣的:(Java取得日期时间的代码)