84 lines
1.8 KiB
Java
84 lines
1.8 KiB
Java
package com.example.sso.util;
|
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.ZoneId;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.Locale;
|
|
|
|
public class TimeUtil {
|
|
/**
|
|
* 由于时区的原因,调整时区
|
|
* @return
|
|
*/
|
|
|
|
public static String nowmonth(){
|
|
// 获取当前时间
|
|
// 获取当前的日期和时间
|
|
LocalDateTime now = LocalDateTime.now();
|
|
// 获取当前日期
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
|
// 创建一个日期格式化器,按照"yyyy-MM"的格式
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
|
// 格式化当前日期
|
|
String formattedDate = currentDate.format(formatter);
|
|
|
|
|
|
|
|
return formattedDate;
|
|
}
|
|
|
|
|
|
|
|
public static String two(){
|
|
// 获取当前时间
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
// 向前推6个小时
|
|
LocalDateTime adjustedDateTime = now.minusHours(6);
|
|
|
|
// 格式化输出
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
String formattedDateTime = adjustedDateTime.format(formatter);
|
|
|
|
|
|
|
|
return formattedDateTime;
|
|
}
|
|
|
|
|
|
|
|
public static String now(){
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
// 向前推6个小时
|
|
LocalDateTime adjustedDateTime = now.minusHours(8);
|
|
|
|
// 格式化输出
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
String formattedDateTime = adjustedDateTime.format(formatter);
|
|
|
|
|
|
|
|
return formattedDateTime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|