1
zj
2026-06-01 1f19b78818609bf6d0849f8e58b349132a800538
src/main/java/com/nq/utils/DateTimeUtil.java
@@ -13,6 +13,9 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
@@ -202,6 +205,32 @@
        return false;
    }
    public static boolean isCanSellOneday(Date buyDate, int day) {
        try{
            LocalDateTime buyTime = buyDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
            LocalDateTime futureDate = buyTime.plusDays(day);
            LocalDateTime zeroTime = futureDate.truncatedTo(ChronoUnit.DAYS);
            Long buyDateTimes = Long.valueOf(zeroTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000L);
            Long nowDateTimes = Long.valueOf((new Date()).getTime() / 1000L);
            if (nowDateTimes.longValue() > buyDateTimes.longValue()) {
                return false;
            }
            return true;
        }catch (Exception e){
            return true;
        }
    }
    /** T+1:买入当日不可卖出,下一交易日方可平仓 */
    public static boolean canSellByT1(Date buyDate) {
        if (buyDate == null) {
            return true;
        }
        return !sameDate(getCurrentDate(), buyDate);
    }
    /*日期年月日是否相同*/
    public static boolean sameDate(Date d1, Date d2) {
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");