package com.javabase.sss;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.xml.crypto.Data;
public class Caler {
public static void main(String[] args) {
//日历类 单例模式
Calendar ca = Calendar.getInstance();
int iYear = ca.get(Calendar.YEAR);
int iMonth = ca.get(Calendar.MONTH)+1;
int iDay = ca.get(Calendar.DAY_OF_MONTH);
int iHour = ca.get(Calendar.HOUR_OF_DAY);
int iMinute = ca.get(Calendar.MINUTE);
int iSecond = ca.get(Calendar.SECOND);
int iMillisecond = ca.get(Calendar.MILLISECOND);
System.out.printf("%d-%02d-%02d %02d:%02d:%02d-%d \n",
iYear,iMonth,iDay,iHour,iMinute,iSecond,iMillisecond
);
//获取当前时间
Date date = new Date();
SimpleDateFormat sTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss-sss");
System.out.println(sTime.format(date));
}
}
java日历类Calendar获取时间
最新推荐文章于 2023-10-16 10:08:51 发布