java 精確獲取時分秒


 1 import java.util.Calendar;
2 import java.util.GregorianCalendar;
3 public class systemdemo {
4 public static void main(String[] args) {
5 Calendar calendar=null;
6 calendar =new GregorianCalendar();//子類實例化
7 System.out.println("年: "+calendar.get(Calendar.YEAR));
8 System.out.println("月 "+(calendar.get(Calendar.MONTH)+1));
9 System.out.println("日: "+calendar.get(Calendar.DAY_OF_MONTH));
10 System.out.println("時: "+calendar.get(Calendar.HOUR_OF_DAY));
11 System.out.println("分: "+calendar.get(Calendar.MINUTE));
12 System.out.println("秒: "+calendar.get(Calendar.SECOND));
13 System.out.println("毫秒 "+calendar.get(Calendar.MILLISECOND));
14
15 }
16 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM