社区Sqlite NOT处理日期&正确的日期时间 [英] Community Sqlite NOT Handling Dates & DateTimes Correctly
问题描述
该新版本似乎无法正确处理日期.请查看以下观察结果:
It seems that this new version is not handling dates correctly. Please see the below observations:
1)使用以下内容时:
1) When using the below:
_conn.Create<MyTable>();
并且我在 MyTable 类中有一个 DateTime 字段,然后将其创建为SQLite数据库内的 BIGINT 列.
And I have a DateTime field in MyTable class, then, it's creating it as BIGINT column inside the SQLite DB.
2)如果我将 BIGINT 列更改为日期时间-以匹配 MyTable 中的 DateTime 定义类-现有的任何行都将读为 01/01/0001 !
2) If I change the BIGINT column to a datetime-to match the DateTime definition in MyTable class-any existing rows are read back as 01/01/0001!
3)如果我尝试将日期值保存到该datetime字段中,请说将其设置为 DateTime.今天,它将其保存为 30-12-1899 .尝试保存什么值都没有关系.它始终保存为 30-12-1899 .
3) If I try to save a date value into that datetime field, say, set it to DateTime.Today it's saving it as 30-12-1899. And it doesn't matter what value you try to save. It's always saved as 30-12-1899.
注意::我正在Android上使用MVVMCross.
NOTE: I'm using MVVMCross on Android.
T.I.A.
推荐答案
SQLite-net
代码中有很长的一段关于应如何存储DateTime的故事.
There's a long story in the SQLite-net
code about how DateTime should be stored.
您可以阅读有关此内容的更多信息,并在 https://github上找到大量意见和链接. com/MvvmCross/MvvmCross/issues/213
You can read more about this and find plenty of opinions and links on https://github.com/MvvmCross/MvvmCross/issues/213
作为此讨论的结果,新的SQLite端口使用StoreDateTimeAsTicks
作为默认设置.
As a result of this discussion, the new SQLite port uses StoreDateTimeAsTicks
as it's default setting.
鉴于人们对上述github问题线程的看法很重要,我建议使用StoreDateTimeAsTicks
设置.如果有错误(如您在3中建议的那样),那么我建议通过SQLite-net社区进行遍历-包括有关所使用的平台和版本的详细信息.
Given the weight of opinions from people on the above github issues thread, I'd recommend using the StoreDateTimeAsTicks
setting. If there are bugs (as you suggest in 3) then I'd recommend chasing this through with the SQLite-net community - including details about the platform and version you are using.
如果您想更改此设置,则可以传入:
If you want to change this setting, then you can pass in:
options.StoreDateTimeAsTicks = false
到SQLite工厂.
For more info on options see: https://github.com/MvvmCross/MvvmCross-SQLite/blob/master/Sqlite/Cirrious.MvvmCross.Community.Plugins.Sqlite/BaseClasses.cs#L27
这篇关于社区Sqlite NOT处理日期&正确的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!