40 lines
841 B
Java
40 lines
841 B
Java
|
package com.jwl.driver.server.util;
|
||
|
|
||
|
import java.time.LocalDateTime;
|
||
|
import java.time.format.DateTimeFormatter;
|
||
|
|
||
|
/**
|
||
|
* @Author: yangshuang
|
||
|
* @Description:
|
||
|
* @Date: 2021/2/23 15:23
|
||
|
* @Version: 1.0
|
||
|
*/
|
||
|
public class DateTimeUtil {
|
||
|
|
||
|
/**
|
||
|
* 时间转字符串
|
||
|
* @param dateTime
|
||
|
* @return
|
||
|
*/
|
||
|
public static String dateTime2Str(LocalDateTime dateTime, DateTimeFormatter df) {
|
||
|
return df.format(dateTime);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 字符串转时间
|
||
|
* @param str
|
||
|
* @return
|
||
|
*/
|
||
|
public static LocalDateTime str2DateTime(String str, DateTimeFormatter df) {
|
||
|
return LocalDateTime.parse(str, df);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取当前时间字符串
|
||
|
* @return
|
||
|
*/
|
||
|
public static String getCurrentStr(DateTimeFormatter df) {
|
||
|
return dateTime2Str(LocalDateTime.now(), df);
|
||
|
}
|
||
|
}
|