Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Android Room在SQLite中存储LocalDate的好数据类型是什么?_Java_Android_Sqlite_Android Room - Fatal编程技术网

Java 使用Android Room在SQLite中存储LocalDate的好数据类型是什么?

Java 使用Android Room在SQLite中存储LocalDate的好数据类型是什么?,java,android,sqlite,android-room,Java,Android,Sqlite,Android Room,目前,我们需要在SQLite中存储假日信息 我们更喜欢在应用程序代码中使用LocalDate 因为,圣诞节总是发生在2020年12月25日,不管用户来自英国还是泰国 在SQLite端,我们倾向于不将其存储在INTEGER时间戳中,因为这需要正确的时区信息 到目前为止,我们选择将其存储在文本中 public class LocalDateConverter { // 2020-12-25 // 2019-11-08 private static final ThreadL

目前,我们需要在SQLite中存储假日信息

我们更喜欢在应用程序代码中使用
LocalDate

因为,圣诞节总是发生在2020年12月25日,不管用户来自英国还是泰国

在SQLite端,我们倾向于不将其存储在
INTEGER
时间戳中,因为这需要正确的时区信息

到目前为止,我们选择将其存储在
文本中

public class LocalDateConverter {
    // 2020-12-25
    // 2019-11-08

    private static final ThreadLocal<DateTimeFormatter> threadLocal = ThreadLocal.withInitial(() -> {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.US);
        return formatter;
    });

    @TypeConverter
    public static String toString(LocalDate localDate) {
        return threadLocal.get().format(localDate);
    }

    @TypeConverter
    public static LocalDate toLocalDate(String string) {
        return LocalDate.parse(string, threadLocal.get());
    }
}
public类LocalDateConverter{
// 2020-12-25
// 2019-11-08
private static final ThreadLocal ThreadLocal=ThreadLocal.withInitial(()->{
DateTimeFormatter formatter=模式的DateTimeFormatter.of(“yyyy-MM-dd”,Locale.US);
返回格式化程序;
});
@类型转换器
公共静态字符串toString(LocalDate LocalDate){
返回threadLocal.get().format(localDate);
}
@类型转换器
公共静态LocalDate到LocalDate(字符串){
返回LocalDate.parse(string,threadLocal.get());
}
}
我在想,这是个好办法吗


在SQLite中是否有更好的数据类型可以使用Android Room存储
LocalDate

是的,
TEXT
作为ISO8601字符串是最好的选择。