Sqlite 如何通过moorselectapi将sqllite日期时间转换为localtime

Sqlite 如何通过moorselectapi将sqllite日期时间转换为localtime,sqlite,flutter,flutter-moor,Sqlite,Flutter,Flutter Moor,我正在使用flatter和moor作为数据库库构建一个移动应用程序。我必须提取特定月份的所有交易记录。我的问题如下 Future<List<Transaction>> fetchTransactionsByCategory( String name, DateTime reportDate) { return (select(transactions) ..where((i) { final date = i.date;

我正在使用flatter和moor作为数据库库构建一个移动应用程序。我必须提取特定月份的所有交易记录。我的问题如下

Future<List<Transaction>> fetchTransactionsByCategory(
  String name, DateTime reportDate) {
  return (select(transactions)
      ..where((i) {
        final date = i.date;
        return date.year.equals(reportDate.year) &
            date.month.equals(reportDate.month) &
            i.subCategory.equals(name);
      }))
    .get();
Future fetchTransactionsByCategory(
字符串名称,日期时间报告日期){
返回(选择(事务)
…其中((i){
最终日期=i.日期;
返回日期.year.equals(reportDate.year)&
date.month.equals(reportDate.month)&
i、 子类别。等于(名称);
}))
.get();
}

问题是,如果交易时间为2021年5月1日12:00:00 AM,则不属于5月报告,而是属于4月报告。我能够理解在数据库中,它被持久化为2021年4月30日下午16:00:00(这里的时区+8)


如何编写查询以根据本地时区获取事务?有什么建议吗?

在您的pubspec
intl:^0.16.1
进口

import 'package:intl/intl.dart';
在你的最高状态(第一状态)

然后你可以像这样使用它

@override
void initState() {
 super.initState();
 initializeDateFormatting();
}

你想解释什么?我不明白。问题在查询级别。