- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建全年日历,如何在 Flutter 中获取每月的天数?
例如,一月 -> 31,二月 -> 28/29(每年),三月 -> 31 等等......
最佳答案
您可以使用包 https://pub.dev/packages/date_util
使用 dateUtility.daysInMonth
代码片段
var dateUtility = DateUtil();
var day1 = dateUtility.daysInMonth(2, 2019);
print(day1);
var day2 = dateUtility.daysInMonth(2, 2018);
print(day2);
import 'package:flutter/material.dart';
import 'package:date_util/date_util.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
var dateUtility = DateUtil();
var day1 = dateUtility.daysInMonth(2, 2019);
print(day1);
var day2 = dateUtility.daysInMonth(2, 2018);
print(day2);
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
I/flutter (11462): 28
I/flutter (11462): 28
关于flutter - 如何在 Dart/Flutter 中获取整个月的天数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58762347/
我的目标是获取购买给定产品所需的平均天数。如果 Product_A 在给定时间段内购买了 3 次(“2012-12-01”、“2012-12-05”、“2012-12-10”),那么我们的平均订单间隔
我在计算利息天数时有一个有趣的错误。我每天检查并检查今天是哪一天(1 到 31)。现在我发现了一个问题:10月计数不正常。这意味着 27 号是 26 号,或者 29 号是 28 号。这是一个众所周知的
你好我一直在做一些程序,我的程序是获取一年中过去的天数。现在,当我尝试运行时,输出结果为“4438232”。 例如,如果用户输入 (mm-dd-yy) 3-18-2013,则该年经过的扩孔天数为 77
我看到此问题已针对 Java 得到解答, JavaScript , 和 PHP ,但不是 C#。那么,如何在 C# 中计算两个日期之间的天数? 最佳答案 假设 StartDate 和 EndDate
QQ每天抽超级会员成长值、天数 非必中 手Q打开链接进入活动,下拉页面随便分享一下领取抽奖机会,亲测3点成长值! 活动地址:https://sourl.cn/37CZad 手Q扫码:
是否有任何内置函数可以找出时间戳之间的天数、添加天数或查找时间戳之间的月数?目前,我将日期作为字符串存储在我的文档中。 例如,如果我这样做: return (DATE_TIMESTAMP("2014-
我无法弄清楚如何为以下场景编写公式。我需要根据另一列计算日期,但需要根据原始列的星期几添加天数。 If day of week equals 'Mon/Wed/Fri/Sat' then add 5
我有两个系列的 Pandas 约会时间。我为数据框中的每一行减去它们,并添加一列以获取两个日期时间之间的时间增量。随后我想使用该时间增量来扩展另一个功能。所以我想对那个时间增量进行一些划分。没有骰子。
这个问题已经有答案了: "cannot find symbol: method" but the method is declared (3 个回答) How to add one day to a
我的代码是这样的,但第三行出错 mm/dd/yyyy 我的数据库日期格式如下: SELECT evep year(date='MM/dd/yyyy'), month(da
我有两个 jQuery UI 日期选择器,当它们都选择了日期时,我希望这些日期之间的差异显示在单独的 input[type="text"] 一旦选择了第二个日期。 此外,理想情况下,我希望我的计数减去
我有两列:rental_date 和 actual_retdate。我需要找到 actual_retdate 和 rental_date 之间的天数。 actual_retdate 在某些情况下可以为
运行 MySql 和 Yii 我需要更改当前查找当月记录的关系查询以查找过去 45 天的所有记录。 这是我当前的查询: 'itemCount' => array(self::STAT, 'It
我想创建一个新列,它将显示两个日期之间的时间增量(以天为单位),如以下 pandas 数据框所示: >>> hg[['not inc','date']] not inc
我有: 年份数字(可以是任何年份) 月份数(从一月到十二月) 周数(第 1、2、3、4、最后) 工作日(周日、周一、周二、周三、周四、周五、周六) 我需要获取天数 [从 1 到 ~31] - "YYY
我需要为一些项目倒数 90 天、120 天和 160 天。我将如何编码?我一直在寻找 java 代码,但是在我为 android 开发时会出现错误。 我需要用今天的日期减去 x 天,然后将结果显示在屏
我的要求是计算给定的两个日期之间的天数,不包括星期六和星期日。 示例: Start date - 10/09/15 and End date 18/09/15 Result: 7 日期采用 DD/MM
我想比较我的 Android 应用程序的两个日期,但我遇到了一个非常奇怪的问题。 例如: 如果我将 回到过去 日期设置为 127 天前: this.dateEvent = System.current
如何返回所提供日期的 CumSum 天数? import pandas as pd df = pd.DataFrame({ 'date': ['2019-01-01','2019-01-03'
例如,我可以使用以下代码获取当前日期以显示在 DatePicker 对话框中。 final Calendar c = Calendar.getInstance(); mYear = c
我是一名优秀的程序员,十分优秀!