first commit
This commit is contained in:
83
src/main/java/com/example/sso/util/TimeUtil.java
Normal file
83
src/main/java/com/example/sso/util/TimeUtil.java
Normal file
@ -0,0 +1,83 @@
|
||||
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;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user