Java中获取当前时间并格式化
Java中获取当前时间并格式
import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); System.out.println(sdf.format(calendar.getTime())); // 输出 2020-10-20 20:17:31 } }