獲取伺服器時間
阿新 • • 發佈:2021-10-17
獲取伺服器時間
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); } }