文章目录
LocalDateTIme
获取当前时间后一年的时间戳
LocalDateTime.now().plusYears(1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
获取当前时间的格式化时间
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
时间戳转换时间点
//时区加8
LocalDateTime.ofEpochSecond(this.timestamp, 0, ZoneOffset.ofHours(8));
postgre SQL数据库
时间戳转换为时间
//时间格式
to_timestamp(time)
//字符串格式
to_char(to_timestamp(time),'yyyy-MM-dd HH24-MI-SS')
将LocalDateTime转为字符串
public PollutantInstatValue getInstantValue(String district, LocalDateTime hour) {
String hourString = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(hour);
return mapper.getDistrictInstantValue(district, hourString);
}
求某个时间点的整点
SELECT date_trunc('hour', timestamp) FROM air_sensor_recode;
不是四舍五入
同理 整数天的时间点也可也求出来
求按小时分组的最后一个时间点
SELECT date_trunc('hour', timestamp) AS hour, last(timestamp, timestamp) as "reportTime" FROM air_sensor_recode GROUP BY hour;
在java层面求某个时间的整点
Local