java Calendar(将时间精确到毫秒)

package com.neusoft.date;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class RiQi
{
  public static void main(String []args){
      System.out.println(new Date());
      //calendar可以将时间精确到毫秒
      Calendar calendar = new GregorianCalendar();
      System.out.println("年:"+calendar.get(Calendar.YEAR));
      System.out.println("月:"+(calendar.get(Calendar.MONTH)+1));
      System.out.println("日:"+calendar.get(Calendar.DAY_OF_MONTH));
      System.out.println("时:"+calendar.get(Calendar.HOUR_OF_DAY));
      System.out.println("分:"+calendar.get(Calendar.MINUTE));
      System.out.println("秒:"+calendar.get(Calendar.SECOND));
      System.out.println("毫秒:"+calendar.get(Calendar.MILLISECOND));
  }
}

posted @ 2020-12-25 16:15  路要一步一步走  阅读(2960)  评论(0编辑  收藏  举报