当前位置: 首页 > wzjs >正文

做网站把自己做死wordpress网站回调域

做网站把自己做死,wordpress网站回调域,黄山景区的网站做的怎么样,中山网页设计公司C 的 <chrono> 库是一个强大的时间处理库&#xff0c;提供了高精度的时间测量、时钟操作和时间点计算功能。 1. 基本概念 1.1 时间单位&#xff08;Duration&#xff09; std::chrono::duration 表示时间间隔&#xff0c;由 计数值 和 时间单位 组成。 常用类型&…

C++ 的 <chrono> 库是一个强大的时间处理库,提供了高精度的时间测量、时钟操作和时间点计算功能

1. 基本概念

1.1 时间单位(Duration)

std::chrono::duration 表示时间间隔,由 计数值时间单位 组成。

  • 常用类型
    using nanoseconds  = duration<long long, nano>;      // 纳秒
    using microseconds = duration<long long, micro>;     // 微秒
    using milliseconds = duration<long long, milli>;     // 毫秒
    using seconds      = duration<long long>;            // 秒
    using minutes      = duration<int, ratio<60>>;       // 分钟
    using hours        = duration<int, ratio<3600>>;     // 小时
    
  • 自定义 Duration
    using days = duration<int, ratio<86400>>;  // 天(24*60*60秒)
    
  • 转换
    seconds s(1);
    milliseconds ms = duration_cast<milliseconds>(s);  // 显式转换
    auto ms_approx = s * 1000;  // 隐式转换(可能截断)
    
1.2 时间点(Time Point)

std::chrono::time_point 表示某个特定时刻,由 时钟类型时间间隔 组成。

  • 常用操作
    using namespace std::chrono;
    time_point<system_clock> now = system_clock::now();  // 当前时间点
    time_point<system_clock> later = now + hours(1);      // 1小时后
    duration<double> diff = later - now;                  // 时间差(秒)
    
1.3 时钟(Clock)

时钟提供当前时间点,包含三个关键类型:

  • now():返回当前时间点。
  • duration:时钟的时间单位。
  • is_steady:是否为稳定时钟(即时间是否单调递增)。

三种标准时钟

  1. system_clock:系统实时时钟,支持与 time_t 互转:
    time_t t = system_clock::to_time_t(now);  // 转 time_t
    time_point<system_clock> tp = system_clock::from_time_t(t);  // 转 time_point
    
  2. steady_clock:稳定时钟,适合测量时间间隔(如性能测试):
    auto start = steady_clock::now();
    // ... 代码执行 ...
    auto end = steady_clock::now();
    cout << "耗时: " << duration_cast<milliseconds>(end - start).count() << "ms\n";
    
  3. high_resolution_clock:高精度时钟(通常是 system_clocksteady_clock 的别名)。

2. 高级用法

2.1 自定义时钟

通过继承 std::chrono::clock 可以创建自定义时钟:

struct my_clock {using duration = std::chrono::milliseconds;using rep = duration::rep;using period = duration::period;using time_point = std::chrono::time_point<my_clock>;static constexpr bool is_steady = true;static time_point now() noexcept;  // 实现当前时间获取
};
2.2 休眠与等待

结合 std::this_thread::sleep_forstd::condition_variable 使用:

// 休眠3秒
std::this_thread::sleep_for(seconds(3));// 等待条件变量,最多500毫秒
std::condition_variable cv;
std::mutex m;
bool ready = false;
cv.wait_for(std::unique_lock<std::mutex>(m), milliseconds(500), [&]{ return ready; });
2.3 时间点算术

支持时间点的加减运算:

time_point<steady_clock> tp = steady_clock::now();
tp += minutes(2) + seconds(30);  // 2分30秒后
tp -= hours(1);                  // 1小时前

3. C++20 新增特性

3.1 日历与时区

引入 std::chrono::zoned_time 和日历组件(如 year_month_day):

#include <chrono>
#include <iostream>using namespace std::chrono;int main() {// 当前时间点auto now = system_clock::now();// 获取本地时区auto local_tz = current_zone();// 转换为本地时间zoned_time local_time(local_tz, now);std::cout << "本地时间: " << local_time << '\n';// 构建特定日期auto date = year(2023) / month(10) / day(1);std::cout << "日期: " << date << '\n';return 0;
}
3.2 格式化输出

使用 std::formatstd::chrono::format 格式化时间点:

auto now = system_clock::now();
std::cout << std::format("{:%Y-%m-%d %H:%M:%S}", now);  // 输出:2023-10-01 12:34:56

4. 性能考虑

  • 精度与开销:高精度时钟(如 high_resolution_clock)可能有更高的系统开销。
  • 跨平台差异:不同系统的时钟实现可能有细微差异,尤其是 high_resolution_clock

5. 常见应用场景

  1. 性能测试
    auto start = steady_clock::now();
    // 执行测试代码
    auto end = steady_clock::now();
    std::cout << "代码执行耗时: " << (end - start).count() << "纳秒\n";
    
  2. 超时控制
    future<int> f = std::async([]{ return 42; });
    if (f.wait_for(seconds(1)) == std::future_status::ready) {std::cout << "结果: " << f.get() << '\n';
    } else {std::cout << "超时\n";
    }
    

总结

<chrono> 库通过 durationtime_pointclock 三个核心组件,提供了类型安全、高精度的时间处理能力。从简单的时间间隔测量到复杂的时区转换,该库覆盖了几乎所有时间相关的场景,是现代 C++ 开发中不可或缺的工具。


文章转载自:

http://h8mVEIBY.hLfrh.cn
http://O8e80P0E.hLfrh.cn
http://xLer04ao.hLfrh.cn
http://zkaJ0PLS.hLfrh.cn
http://G54sBuJT.hLfrh.cn
http://J7sJsYZh.hLfrh.cn
http://dVufR5oE.hLfrh.cn
http://5gHfuear.hLfrh.cn
http://poPZPHhN.hLfrh.cn
http://pbWDBoL8.hLfrh.cn
http://VMVBOH2y.hLfrh.cn
http://eMJtfqXA.hLfrh.cn
http://vKQkD0Si.hLfrh.cn
http://H2a9qJCo.hLfrh.cn
http://1tUkiTDo.hLfrh.cn
http://DXFPMCxl.hLfrh.cn
http://1rPsvmiy.hLfrh.cn
http://vK3PjbKz.hLfrh.cn
http://qPG4Bzmb.hLfrh.cn
http://iN7HbpVZ.hLfrh.cn
http://YfZu7Ih6.hLfrh.cn
http://FZYUWPHA.hLfrh.cn
http://B3CcS1FZ.hLfrh.cn
http://jh7uM5JI.hLfrh.cn
http://JLPHrY6O.hLfrh.cn
http://SiBfmiCF.hLfrh.cn
http://Ik0CyQGK.hLfrh.cn
http://mC7N4WWl.hLfrh.cn
http://V4LFRtAC.hLfrh.cn
http://byR71ayv.hLfrh.cn
http://www.dtcms.com/wzjs/661182.html

相关文章:

  • 青海建设银行的官方网站有网站前台如何做后台
  • 网站建设的总结100字2024年小微企业100至300万
  • 企业网站推广哪家好html5网站模板
  • 文昌网站建设 myvodo网站开发后所有权
  • 天津营销网站建设梅江区建设局网站
  • 湖州外贸网站建设死链接对网站的影响
  • 网站app建设图片素材部署wordpress站点
  • 企业网站的作用有哪些深圳建设网站和公众号
  • 装饰网站卧室做炕百度专业版简历
  • 上海建设网站公司哪家好中国食品网
  • 有名设计网站做网站的公司多吗
  • 中国建设银行理财网站深圳市建设工程合同备案网站
  • 做旅游去哪个网站找图上海建设银行长宁区各分行网站
  • 教做世界美食的网站方维服务客户类型
  • 大学生毕业设计网站cms wordpress 企业
  • 怎么样利用一些网站开发客户自己安装wordpress
  • 9e做网站wordpress屏蔽国外访问
  • 免费的cms视频网站模板网页制作图片教程
  • 电子商务网站建设与维护管理百度广告位价格
  • 深圳市建设局官方网站我的个人网页设计效果图
  • 2017免费网站空间网站建设创新互联
  • 爱站网怎么用做网站中app客户端
  • 中国建设银行官网招聘信息上海网站排名优化公司
  • python做网站是不是特别慢百度地图怎么没有实景导航了
  • 西宁做网站制作的公司网站售后服务内容
  • 旅行网站信息技术化建设投资交易网站开发
  • 优设网站官网网站怎么更换服务器
  • 怎么搭建一个网站淘宝客网站建设详细教程
  • 文化传媒公司网站模板网站如何做竟价
  • 域名备案查询网站备案素马设计官网