在Java中,可以使用java.util.Date类和java.text.SimpleDateFormat类来打印当前时间。下面是一个示例代码:
import java.util.Date;import java.text.SimpleDateFormat;public class Main {public static void main(String[] args) {Date currentDate = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String currentTime = dateFormat.format(currentDate);System.out.println("当前时间是:" + currentTime);}}上面的代码首先创建一个Date对象表示当前时间,然后使用SimpleDateFormat类将其格式化为一个字符串,并最后打印出来。您可以根据需要自定义日期的格式。
上一篇:shell获取文件名的方法是什么
下一篇:java怎么判断元素是否在集合中
java









