/* * @Author: wangyang 1147192855@qq.com * @Date: 2022-07-13 16:59:53 * @LastEditors: wangyang 1147192855@qq.com * @LastEditTime: 2022-07-13 17:00:56 * @FilePath: \marking_app\lib\utils\common_utils.dart * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ import 'dart:convert'; import 'package:convert/convert.dart'; import 'package:crypto/crypto.dart'; class CommonUtils { // md5 加密 static String generateMD5(String data) { var content = new Utf8Encoder().convert(data); var digest = md5.convert(content); // 这里其实就是 digest.toString() return hex.encode(digest.bytes); } ///补零 static String zeroFill(int i) { return i >= 10 ? "$i" : "0$i"; } /// 秒转时分秒 static String second2HMS(int sec, {bool isEasy = false}) { String hms = "00:00:00"; if (!isEasy) hms = "00时00分00秒"; if (sec > 0) { int h = sec ~/ 3600; int m = (sec % 3600) ~/ 60; int s = sec % 60; /* hms = "${zeroFill(h)}:${zeroFill(m)}:${zeroFill(s)}"; if (!isEasy) hms = "${zeroFill(h)}时${zeroFill(m)}分${zeroFill(s)}秒";*/ if(h>0){ hms = "$h时$m分$s秒"; }else{ if(m>0){ hms = "$m分$s秒"; }else{ hms = "$s秒"; } } } return hms; } }