• 【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());
  • 相关阅读:
    [整理]ADB命令行学习笔记
    3、HTML的body内标签1
    2、HTML的head内标签
    1、HTML的本质以及在web中的作用
    3.11-3.15 HDFS HA
    3.9-3.10 分布式协作服务框架Zookeeper
    3.6-3.8 分布式环境启动、测试
    3.1-3.5 分布式部署hadoop2.x的准备和配置
    2.28 MapReduce在实际应用中常见的优化
    2.27 MapReduce Shuffle过程如何在Job中进行设置
  • 原文地址:https://www.cnblogs.com/lxlx1798/p/11371280.html
Copyright © 2020-2023  润新知