• 【Dart学习】--之Duration相关方法总结


    一,概述

    • Duration表示从一个时间点到另一个时间点的时间差
    • 如果是一个较晚的时间点和一个较早的时间点,Duration可能是负数

    二,创建Duration

    • 唯一的构造函数创建Duration对象
      Duration({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, int milliseconds: 0, int microseconds: 0})
    • 可以使用其中的一个或者几个参数创建
      • 只是用其中的一个参数
        Duration ration = Duration(days: 1);
        print(ration); //24:00:00.000000
        Duration ration1 = Duration(hours: 10);
        print(ration1); //10:00:00.000000
      • 只是用其中的两个参数
        Duration ration2 = Duration(days: 1, hours: 3);
        print(ration2); //27:00:00.000000
      • 使用所有的参数
        Duration ration3 = Duration(days: 2, hours: 2, minutes: 23, seconds: 34, milliseconds: 56, microseconds: 89);
        print(ration3); //50:23:34.056089

    三,相关运算

    • 示例
      Duration time1 = Duration(days: 1, hours: 1, minutes: 1, seconds: 1, milliseconds: 1, microseconds: 1);
      Duration time2 = Duration(days: 2, hours: 2, minutes: 2, seconds: 2, milliseconds: 2, microseconds: 2);
      print(time1); //25:01:01.001001
      print(time2); //50:02:02.002002

      • print(time1 + time2); //75:03:03.003003

      • print(time1 - time2); //-25:01:01.001001

      • print(time1 * 2); //50:02:02.002002
      • 除(取整)
        print(time2 ~/ 3); //16:40:40.667334
      • 比较
        print(time1 > time2); //false
        print(time1 >= time2); //false
        print(time1 == time2); //false
        print(time1 < time2); //true
        print(time1 <= time2); //true
      • 取相反值
        print(-time1); //-25:01:01.001001
        print(-(time1 - time2)); //25:01:01.001001

    四,相关函数

    • 示例
      Duration time3 = -Duration(days: 1, hours: 1, minutes: 1, seconds: 1, milliseconds: 1, microseconds: 1);
      print(time3); //-25:01:01.001001
      • 取绝对值
        print(time3.abs()); //25:01:01.001001
      • 比较, 返回值, 0: 相等, -1: time1 < time2, 1: time1 > time2
        print(time1.compareTo(time2)); //-1
      • 字符串形式
        print(time1.toString());
  • 相关阅读:
    ThinkPHP模版引擎之变量输出具体解释
    Heat-AutoScaling
    開始搭建第一个zookeeper
    OpenCV学习笔记(六十二)——《OpenCV Computer Version with Python》阅读摘要
    Oracle可插拔数据库的jdbc连接串写法
    MVVM设计模式基础知识--ICommand接口
    CodeForces
    一见钟情Sublime
    # 从零開始搭建Hadoop2.7.1的分布式集群
    C语言遍历文件和文件夹——————【Badboy】
  • 原文地址:https://www.cnblogs.com/lxlx1798/p/11371280.html
Copyright © 2020-2023  润新知