This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12567|Reply: 0

[Source] JAVA to get the current system time

[Copy link]
Posted on 8/21/2018 4:37:18 PM | | |
1、Date day=new Date();   

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

System.out.println(df.format(day));   

Date class to get the current time   



2、SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   System.out.println(df.format(System.currentTimeMillis()));   

Get the current time via the currentTimeMillis method in the System class



3、Calendar c = Calendar.getInstance(); Can be modified individually for each time domain   

int year = c.get(Calendar.YEAR);  

int month = c.get(Calendar.MONTH);   

int date = c.get(Calendar.DATE);   

int hour = c.get(Calendar.HOUR_OF_DAY);   

int minute = c.get(Calendar.MINUTE);   

int second = c.get(Calendar.SECOND);   

System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);   

Use the Calendar class to get the current time   



4、 Date date = new Date();   

String year = String.format("%tY", date);   

String month = String.format("%tB", date);   

String day = String.format("%te", date);   

System.out.println("Today is:"+year+"-"+month+"-"+day);   

Date class to get the current time   



Summary: Setting the time format can be set by calling the SimpleDateFormat class and by using the format method in String. This can be obtained via the Date class and currentTimeMillis in System!




Previous:IntelliJ idea smart hint ignores case settings
Next:Spring Boot application.yml application.properties priority
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com