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

数据库在网站建设中的作用wordpress 免费中文企业主题下载

数据库在网站建设中的作用,wordpress 免费中文企业主题下载,群晖docker wordpress,微信公众号怎么二次开发1.前言 对于linux下的编程#xff0c;无论是用户态还是内核态#xff0c;时间获取都是经常需要使用到的。以下分别从用户态和内核态整理了几个常用的时间获取接口#xff0c;供编写代码时快速查阅。 2.用户态获取时间 2.1 clock_gettime() #include time.hint c…1.前言 对于linux下的编程无论是用户态还是内核态时间获取都是经常需要使用到的。以下分别从用户态和内核态整理了几个常用的时间获取接口供编写代码时快速查阅。 2.用户态获取时间 2.1 clock_gettime() #include time.hint clock_gettime (clockid_t __clock_id, struct timespec *__tp);作用根据系统时钟的类型获取当前时间__clock_id系统时钟的类型。常用取值 CLOCK_REALTIME: 从1970年1月1日到目前的时间CLOCK_MONOTONIC: 系统启动时间CLOCK_PROCESS_CPUTIME_ID: 本进程运行时间CLOCK_THREAD_CPUTIME_ID: 本线程运行的时间 __tp: 存放当前的时间。返回值成功则返回0失败则返回-1 timespec结构体 struct timespec {__time_t tv_sec; /* Seconds. 秒 */__syscall_slong_t tv_nsec; /* Nanoseconds. 纳秒*/ };示例 #include stdio.h #include string.h #include time.hlong long get_clock_sys_time_ns(void) {struct timespec tp;long long time_ns 0;clock_gettime(CLOCK_MONOTONIC, tp);time_ns (long long)tp.tv_sec * 1000000000 tp.tv_nsec;return time_ns; }int main(void) {struct timespec tp;/// 获取从1970年1月1日到目前的时间memset(tp, 0, sizeof(struct timespec));clock_gettime(CLOCK_REALTIME, tp);printf(clock_id CLOCK_REALTIME, sec %ld, nsec %ld\n, tp.tv_sec, tp.tv_nsec);/// 获取系统启动时间memset(tp, 0, sizeof(struct timespec));clock_gettime(CLOCK_MONOTONIC, tp);printf(clock_id CLOCK_MONOTONIC, sec %ld, nsec %ld, sys_time %lld ns\n, tp.tv_sec, tp.tv_nsec, get_clock_sys_time_ns());/// 获取本进程运行时间memset(tp, 0, sizeof(struct timespec));clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tp);printf(clock_id CLOCK_PROCESS_CPUTIME_ID, sec %ld, nsec %ld\n, tp.tv_sec, tp.tv_nsec);/// 获取本线程运行时间memset(tp, 0, sizeof(struct timespec));clock_gettime(CLOCK_THREAD_CPUTIME_ID, tp);printf(clock_id CLOCK_THREAD_CPUTIME_ID, sec %ld, nsec %ld\n, tp.tv_sec, tp.tv_nsec);return 0; }2.2.gettimeofday() #include sys/time.hint gettimeofday(struct timeval *tv, struct timezone *tz);作用获取当前时间从1970年1月1日到目前的时间tv当前UTC时间tz当前时区信息返回值成功则返回0失败则返回-1 timeval结构体 struct timeval {__time_t tv_sec; /* Seconds. 秒*/__suseconds_t tv_usec; /* Microseconds. 微秒*/ };timezone结构体 struct timezone{int tz_minuteswest; /* Minutes west of GMT. 和Greenwich时间差了多少分钟 */int tz_dsttime; /* Nonzero if DST is ever in effect. 日光节约时间的状态 */};示例 #include stdio.h #include string.h #include sys/time.hlong long get_sys_time_ms(void) {long long time_ms 0;struct timeval tv;gettimeofday(tv, NULL);time_ms ((long long)tv.tv_sec*1000000 tv.tv_usec) / 1000;return time_ms; }int main(void) {/// 获取系统时间printf(sys_time %lld ms\n, get_sys_time_ms());return 0; }2.3.time() #include time.htime_t time(time_t *tloc);作用获取1970-01-01 00:00:00 0000至今的秒数UTCtloc返回的秒存储指针返回值成功则返回秒数失败则返回-1错误原因存在errno中。 time_t的类型 typedef long time_t;示例 #include stdio.h #include time.htime_t get_utc_time(void) {return time(NULL); }int main(int argc, char **argv) {time_t utc_time get_utc_time();printf(utc_time %ld s\n, utc_time);return 0; }2.4.localtime() #include time.hstruct tm *localtime(const time_t *timep);作用将time_t类型的时间转换为struct tm类型的时间timep当前UTC秒数返回值返回当地时间 tm结构体 struct tm {int tm_sec; /* Seconds. [0-60] (1 leap second) */int tm_min; /* Minutes. [0-59] */int tm_hour; /* Hours. [0-23] */int tm_mday; /* Day. [1-31] */int tm_mon; /* Month. [0-11] 注意0代表1月以此类推*/int tm_year; /* Year - 1900. 该值为实际年份减去1900*/int tm_wday; /* Day of week. [0-6] 注意0代表星期一以此类推*/int tm_yday; /* Days in year.[0-365] 从每年的1月1日开始的天数其中0代表1月1日以此类推*/int tm_isdst; /* DST. [-1/0/1] 夏玲时标识符*/ };示例 #include stdio.h #include time.htime_t get_utc_time(void) {return time(NULL); }int main(int argc, char **argv) {time_t utc_time get_utc_time();printf(utc_time %ld s\n, utc_time);struct tm *local_tm localtime(utc_time); printf(local time %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n, local_tm-tm_year 1900,local_tm-tm_mon 1,local_tm-tm_mday,local_tm-tm_hour,local_tm-tm_min,local_tm-tm_sec);return 0; }2.5.localtime_r() #include time.hstruct tm *localtime_r(const time_t *timep, struct tm *result);作用将time_t类型的时间转换为struct tm类型的时间timep当前UTC秒数result当地时间返回值返回当地时间 注 localtime不是一个线程安全的函数。对于实时性要求较高的系统多个线程同时调用localtime可能会造成数据被覆盖。使用localtime_r来替代。 示例 #include stdio.h #include time.htime_t get_utc_time(void) {return time(NULL); }int main(int argc, char **argv) {time_t utc_time get_utc_time();printf(utc_time %ld s\n, utc_time);struct tm result;struct tm *local_tm localtime_r(utc_time, result); printf(local time %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n, local_tm-tm_year 1900,local_tm-tm_mon 1,local_tm-tm_mday,local_tm-tm_hour,local_tm-tm_min,local_tm-tm_sec);printf(result time %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n, result.tm_year 1900,result.tm_mon 1,result.tm_mday,result.tm_hour,result.tm_min,result.tm_sec);return 0; }2.6.gmtime() #include time.hstruct tm *gmtime(const time_t *timep);作用返回tm结构的GMT时间UTC时间timep当前UTC秒数返回值返回当地时间 例子 #include stdio.h #include time.htime_t get_utc_time(void) {return time(NULL); }int main(int argc, char **argv) {time_t utc_time get_utc_time();printf(utc_time %ld s\n, utc_time);struct tm *gmt_tm gmtime(utc_time); printf(gmt time %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n, gmt_tm-tm_year 1900,gmt_tm-tm_mon 1,gmt_tm-tm_mday,gmt_tm-tm_hour,gmt_tm-tm_min,gmt_tm-tm_sec);return 0; }localtime和gmtime的区别: localtime和gmtime都是C语言中的函数用于将time_t类型的时间转换为struct tm类型的时间。它们的区别在于gmtime将time_t转换为UTC时间即世界标准时间而localtime将time_t转换为本地时间。 例子使用gmtime与localtime接口返回的小时数来计算当地时区 #include stdio.h #include time.htime_t get_utc_time(void) {return time(NULL); }int main(int argc, char **argv) {time_t utc_time get_utc_time();printf(utc_time %ld s\n, utc_time);struct tm *gmt_tm gmtime(utc_time); printf(gmt time %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n, gmt_tm-tm_year 1900,gmt_tm-tm_mon 1,gmt_tm-tm_mday,gmt_tm-tm_hour,gmt_tm-tm_min,gmt_tm-tm_sec);int gmt_hour gmt_tm-tm_hour;struct tm *local_tm localtime(utc_time); printf(local time %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n, local_tm-tm_year 1900,local_tm-tm_mon 1,local_tm-tm_mday,local_tm-tm_hour,local_tm-tm_min,local_tm-tm_sec);int local_hour local_tm-tm_hour;int local_time_zone local_hour - gmt_hour;if (local_time_zone -12) {local_time_zone 24; } else if (local_time_zone 12) {local_time_zone - 24;}else{}printf(local_time_zone %d\n, local_time_zone);return 0; }3.内核态获取时间 3.1.do_gettimeofday()比较老的函数新内核可能不存在了 #include linux/time.h void do_gettimeofday(struct timeval *tv);作用与C标准库中gettimeofday()用法相同tv当前UTC时间 timeval结构体 struct timeval {__time_t tv_sec; /* Seconds. 秒*/__suseconds_t tv_usec; /* Microseconds. 微秒*/ };示例 #include linux/module.h #includelinux/time.h MODULE_LICENSE(GPL);int __init do_gettimeofday_init(void) {printk(do_gettimeofday test begin.\n);struct timeval now{.tv_sec0,.tv_usec0}; //声明一个变量do_gettimeofday(now); //调用函数获取时间此时间是距离1970-01-01 00:00:00的时间/*显示当前时间差*/printk(the seconds of the day is: %ld\n, now.tv_sec); //秒数printk(the microseconds of the day is: %ld\n, now.tv_usec); //微秒数printk(do_gettimeofday test over.\n);return 0; }void __exit do_gettimeofday_exit(void) {printk(Goodbye do_gettimeofday test\n); }module_init(do_gettimeofday_init); module_exit(do_gettimeofday_exit);3.2.基于ktime_t格式的时间 参考linux kernel时钟获取 ktime_get() #include linux/ktime.hktime_t ktime_get(void);作用获取的是CLOCK_MONOTONIC时间。通过ktime_get获取的时间是不统计设备休眠时间的并且这个时间统计的起始点则是设备启动后。 返回值返回ktime_t格式的数据类型单位为纳秒。 ktime_t的定义 typedef s64 ktime_t;示例 time_test_drv_init ktime_t curTime 0; curTime ktime_get(); TIME_TEST_INFO(ktime_get:%lld ns, curTime);ktime_get_ts64() #include linux/time64.hvoid ktime_get_ts64(struct timespec64 *ts)作用和ktime_get的功能是完全一样的区别在于对时间的表示数据类型由ktime_t变成了timespec64。 timespec64的定义如下: struct timespec64 {time64_t tv_sec; /* seconds */long tv_nsec; /* nanoseconds */ };timespec64中包含了秒和纳秒相对ktime_t纳秒这个时间表示更加适合人类查看. 示例 static void show_time_ts64(const char* caller, const int line, const struct timespec64 *curTimeTs) {pr_info(%s,%d:%lld s %ld ns\n, caller, __LINE__, curTimeTs-tv_sec, curTimeTs-tv_nsec); }time_test_drv_init struct timespec64 curTimeTs; ktime_get_boottime_ts64(curTimeTs); show_time_ts64(__func__, __LINE__, curTimeTs);3.ktime_get_boottime() static inline ktime_t ktime_get_boottime(void);作用:ktime_get_boottime获取的时间和ktime_get最大的不同是其包含了设备进入休眠的时间其这个时间统计的起始点也是设备启动后。 返回值返回值类型为ktime_t单位为纳秒。 示例 time_test_drv_init ktime_t curTime 0; curTime ktime_get_boottime(); TIME_TEST_INFO(ktime_get_boottime:%lld ns, curTime);4.ktime_get_boottime_ts() void ktime_get_boottime_ts64(struct timespec64 *)作用ktime_get_boottime_ts相对于ktime_get_boottime的功能是完全一样的区别在于对时间的表示数据类型由ktime_t变成了timespec64。 5.ktime_get_real() ktime_t ktime_get_real(void);作用ktime_get_real获取的时间的起点不是设备的启动时间点了而是相对UTC的即从1970开始。 示例 time_test_drv_init ktime_t curTime 0; curTime ktime_get_real(); TIME_TEST_INFO(ktime_get_real:%lld ns, curTime);6.ktime_get_real_ts() void ktime_get_real_ts(struct timespec64 *)作用ktime_get_real_ts相对于ktime_get_real的功能是完全一样的区别在于对时间的表示数据类型由ktime_t变成了timespec64。 示例 time_test_drv_init struct timespec64 curTimeTs; ktime_get_real_ts64(curTimeTs);4.延时函数的实现 void delay_us(uint32_t nus) {volatile uint32_t startts, endts, ts;ts nus;startts get_time_us();endts startts ts;if (endts startts){while (get_time_us() endts);}else{while (get_time_us() endts);while (get_time_us() endts);} }
http://www.hkea.cn/news/14462532/

相关文章:

  • 做企业网站的公司做枸杞的网站
  • 做直播网站有市场吗深圳网站制作首选灵点网络
  • 上海营销型网站建设方案沧州建设银行招聘网站
  • thinkphp做视频网站福州绿光网站建设工作室
  • 苏州建设工程公司网站南昌定制网站开发费用
  • 西安行业网站深圳定制巴士怎么预约
  • 网站项目需求分析怎么做代理网站
  • 湘潭建设企业网站网站制作运营公司
  • 郑州企业网站建站模板网站的倒计时怎么做的
  • 网站开发方案案例d8 wordpress
  • 研学网站开发需求文档网站验证码体验
  • 织梦网站管理安装申请制作网站
  • 钛钢饰品网站建设华为企业邮箱
  • 河南网站建设公司哪个好呀排名sem优化软件
  • 网站的颜色搭配个人网站酷站赏析
  • 百度上面做企业网站怎么做安徽网站建设大全
  • 甘肃张掖网站建设天津做个网站需要多少钱
  • 建构网站西安网页设计及网站建设在线作业
  • nas 做网站源码开发网站建设
  • 自己做的网站链接到微信支付界面自己做网站页面
  • 象刀设计网站浙江省网站集约化建设通知
  • win7 iis网站设置网站建设实训内容
  • 网站建设花费梦幻西游网页版微信区和app互通吗
  • 网站设置qq临时会话吉安网站建设jxthw
  • 湖州网站集约化平台哪些网站做财金的好
  • node.js做的网站比特币支付网站建设
  • 网站主页面设计哪个好怎么制作官网
  • 厚街做网站的公司虚拟币交易网站建设
  • 中国建设银行注册网站用户名怎么填制作app开发制作
  • 青岛当地的做公司网站的wordpress 路径文件大小