Get the current system time (time stamp) in java

Get the current system time in JAVA

Directly upload code and screenshots 

public static void main(String[] args) {

		// 当前时间戳
		System.out.println(System.currentTimeMillis());

		// 参考https://www.cnblogs.com/cai662009/p/8074310.html
		Date now = new Date();
		// 可以方便地修改日期格式
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");

		String currentDate = dateFormat.format(now);
		System.out.println(currentDate);

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

		String currentDate2 = dateFormat2.format(now);
		System.out.println(currentDate2);

	}

The results of the operation are as follows:

Guess you like

Origin blog.csdn.net/czh500/article/details/114892004