获取服务器时间
SysData类
package com.xiang.controller;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
/**
* Created by IntelliJ IDEA.
* User: xiang
* Date: 2021/10/17 16:38
*/
public class SysData {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance(); // get current instance of the calendar
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.println(formatter.format(calendar.getTime()));
System.out.println("/********************************************/");
new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
Date date = new Date(System.currentTimeMillis());
System.out.println(date);
System.out.println("/********************************************/");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
String format = dateFormat.format(date);
System.out.println(format);
System.out.println("/********************************************/");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String s = df.format(date);
System.out.println(s);
System.out.println("/********************************************/");
LocalDateTime.now(); // get the current date and time
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
System.out.println(timeFormatter);
}
}
控制台运行结果
博客连接:
https://www.cnblogs.com/d534/p/15257174.html
https://www.cnblogs.com/d534/p/15254303.html