W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
import java.time.LocalDateTime; // 导入 LocalDateTime 类 import java.time.format.DateTimeFormatter; // 导入 DateTimeFormatter 类 public class Main { public static void main(String[] args) { LocalDateTime myDateObj = LocalDateTime.now(); System.out.println("格式化前: " + myDateObj); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formattedDate = myDateObj.format(myFormatObj); System.out.println("格式化后: " + formattedDate); } } // 注意: 此示例显示的是服务器本地时间,可能与您所在时区的时间不同