获取指定的时间格式
获取指定的时间格式
在 Java 中,你可以使用 java.time 包中的类来获取和格式化当前的日期和时间。以下是如何使用 LocalDateTime 和 DateTimeFormatter 来获取当前的日期和时间,并将其格式化为 "yyyy-MM-dd HH:mm:ss" 格式的示例:
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedNow = now.format(formatter);
System.out.println(formattedNow);
}
}
在上面的代码中,LocalDateTime.now() 获取了当前的日期和时间,然后创建了一个 DateTimeFormatter,它用于将日期和时间转换为特定的字符串格式。最后,使用 now.format(formatter) 将当前的日期和时间转换为你需要的字符串格式。
执行上面的代码,你会看到类似于 "2023-01-13 12:23:32" 格式的当前日期和时间。具体的结果取决于你运行代码的时间。
<where>
<trim prefixOverrides="AND">
<if test="warn.type != null and warn.type != ''">
AND type like '%${warn.type}%'
</if>
<if test="warn.time != null and warn.time != ''">
AND time = '${warn.time}'
</if>
</trim>
</where>
ORDER BY time
浙公网安备 33010602011771号