Tag Archives: LocalDateTime

Java back end receives localdatetime type parameter

//QTO layer

    @ApiModelProperty("Billing start time")
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime billStartTime;
    
    @ApiModelProperty("Billing end time")
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime billEndTime;

@requestBody
@apiOperation (” list”)
stMapping (“/list”)
p>c responseData< PageData< TradeSettlementVO.ListVO> > list(@RequestBody TradeSettlementQTO.PcQTO qto){
return ResponseData.data(ipcMarketSettlementRpc.settlementPageData(qto));
}

Local date time conversion in java8

note : LocalDateTime is

1. LocalDateTime converted to custom time format string

public static String getDateTimeAsString(LocalDateTime localDateTime, String format) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
    return localDateTime.format(formatter);
}

2. Convert long type timestamp to LocalDateTime

public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {
    Instant instant = Instant.ofEpochMilli(timestamp);
    ZoneId zone = ZoneId.systemDefault();
    return LocalDateTime.ofInstant(instant, zone);
}

3. LocalDateTime to long type timestamp

public static long getTimestampOfDateTime(LocalDateTime localDateTime) {
    ZoneId zone = ZoneId.systemDefault();
    Instant instant = localDateTime.atZone(zone).toInstant();
    return instant.toEpochMilli();
}

4. LocalDateTime

converts a time string to a custom time format

public static LocalDateTime parseStringToDateTime(String time, String format) {
    DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
    return LocalDateTime.parse(time, df);
}