Java得到当前系统时间,精确到毫秒的几种方法
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class MainProcess { public static void main(String[] args) { //func1 Calendar Cld = Calendar.getInstance(); int YY = Cld.get(Calendar.YEAR) ; int MM = Cld.get(Calendar.MONTH)+1; int DD = Cld.get(Calendar.DATE); int HH = Cld.get(Calendar.HOUR_OF_DAY); int mm = Cld.get(Calendar.MINUTE); int SS = Cld.get(Calendar.SECOND); int MI = Cld.get(Calendar.MILLISECOND); //由整型而来,因此格式不加0,如 2016/5/5-1:1:32:694 System.out.println(YY + "/" + MM + "/" + DD + "-" + HH + ":" + mm + ":" + SS + ":" + MI); //func2 Calendar cal = Calendar.getInstance(); Date date = cal.getTime(); // 2016/05/05-01:01:34:364 System.out.println(new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss:SSS").format(date)); //func3 2016/05/05-01:01:34:364 System.out.println(new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss:SSS").format(new Date())); } }
相关推荐
Phplayers 2020-09-04
URML 2020-04-22
CodingNotes 2019-11-19
Marsdanding 2019-06-06
kinglee 2019-09-07
DrSmart 2015-08-10
xiaozhifree 2019-07-09
刘炳昭 2019-07-01
AI人工智能 2019-06-28
nxcjh 2019-06-29
mrsuddenflash 2013-09-09
Phplayers 2019-06-28
WindChaser 2019-06-27
pengfeibeiming 2019-06-27
自由飞翔 2014-09-09
solarLan 2019-06-26