写点什么

Flutter OHOS system_boot_time(获取系统启动时间)

作者:flfljh
  • 2024-12-19
    湖南
  • 本文字数:571 字

    阅读完需:约 2 分钟

system_boot_time

获取系统启动时间

用法

import 'package:system_boot_time/system_boot_time.dart';


final second = await SystemBootTime().second();

鸿蒙 OS 代码

获取启动时间

       setup(binaryMessenger: BinaryMessenger, api: SystemBootTime | null): void {{  let channel = new BasicMessageChannel<Object>(binaryMessenger, "dev.flutter.pigeon.SystemBootTime.second", this.getCodec());  if (api != null) {channel.setMessageHandler({  onMessage(msg: Object, reply: Reply<Object>): void {let wrapped = new Map<string, string | number | Map<string, string | number>>();try {  let systemBootTime = api.second();  wrapped.set("result", systemBootTime);} catch (exception) {  let errorMap = new Map<string, string | number>();  errorMap.set("message", exception.message);  errorMap.set("code", exception.name);  errorMap.set("details", `Cause: ${exception.cause}, Stacktrace: ${exception.stack}`);  wrapped.set("error", errorMap);}reply.reply(wrapped);  }});  } else {channel.setMessageHandler(null);  }}  }
复制代码

类型转换

      second(): number {return Math.floor(systemDateTime.getUptime(systemDateTime.TimeType.STARTUP, false) / 1000);  }
复制代码


用户头像

flfljh

关注

还未添加个人签名 2024-10-29 加入

还未添加个人简介

评论

发布
暂无评论
Flutter OHOS system_boot_time(获取系统启动时间)_flfljh_InfoQ写作社区