ESP32需要给下位机通过UART发送时间戳,形式是年月日时分秒的十六进制数据包。

#include <stdio.h>

#include <time.h>

int main()
{
  time_t rawtime;
  struct tm * timeinfo;
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  int year,month,day,hour,min,sec;
  year = +timeinfo->tm_year;
  month = +timeinfo->tm_mon;
  day = timeinfo->tm_mday;
  hour = timeinfo->tm_hour;
  min = timeinfo->tm_min;
  sec = timeinfo->tm_sec;
  printf ( "当前时间:%4d-%02d-%02d %02d:%02d:%02d\n\n",year, month,day,hour,min,sec);
  printf ( "你需要的格式:%4d%02d%02d%02d%02d%02d\n\n",year, month,day,hour,min,sec);   char hyy[],lyy[],MM[],dd[],hh[],mm[],ss[];
  sprintf(hyy,"%02X",year/);
  sprintf(lyy,"%02X",year%);
  sprintf(MM,"%02X",month);
  sprintf(dd,"%02X",day);
  sprintf(hh,"%02X",hour);
  sprintf(mm,"%02X",min);
  sprintf(ss,"%02X",sec);   printf("转化为16进制:%02s%02s%02s%02s%02s%02s%02s\n",hyy,lyy,MM,dd,hh,mm,ss);
  //exit(0);
  return ;
}

C语言 - 获取系统时间 以年月日时分秒的形式输出的更多相关文章

  1. js获取当前时间的年月日时分秒以及时间的格式化

    1.获取当前时间 var myDate = new Date(); 2.获取时间中的年月日时分秒 myDate.getYear(); // 获取当前年份(2位) myDate.getFullYear( ...

  2. java 获取当前时间及年月日时分秒

    java代码如下: package test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.ut ...

  3. [SoapUI] 获取当前时间包括年月日时分秒来作为命名

    import java.text.SimpleDateFormat GregorianCalendar calendar = new GregorianCalendar() def dateForma ...

  4. 在vue项目中显示实时时间(年月日时分秒)

    1.在data中定义一个变量,存储时间 data(){ return { nowTime:'' } }, 2.给定一个div <div>{{nowTime}}</div> 3. ...

  5. Linux C 语言 获取系统时间信息

    比如获取当前年份:        /* 获取当前系统时间 暂时不使用        int iyear = 0;        int sysyear = 0;        time_t now;  ...

  6. C语言 获取系统时间与睡眠时间函数

    摘要: 以ms为单位,获取系统时间.睡眠或延迟时间函数的使用方法. #include<stdio.h> #include <time.h> #include <sys/t ...

  7. js 获取系统时间:年月日 星期 时分秒(动态)

    最近再写一个纯html页面,有时间和天气的数据,天气后台给接口,时间要自己获取,我就自己弄了下, <div class="basic"></div> 这是放 ...

  8. c#.net 获取时间日期年月日时分秒格式

    今天写代码发现两个比较不错的分享下:1.DateTime.ParseExact很多时候我们获取的时间是数字形式表示的,好比20140127134015.927856,通过这个方法DateTime.Pa ...

  9. c#.net 获取时间日期年月日时分秒生成自动文件名格式

    下面是日期和时间的各种方法,转换为字符串. 如果把输出的格式改下就可以做类似的文件名了,例如:2016010110101224356.doc  c#用DateTime.Now.ToString(&qu ...

随机推荐

  1. 前端逼死强迫症系列之javascript续集

    一.javascript函数 1.普通函数 function func(){ } 2.匿名函数 setInterval(function(){ console.log(123); },5000) 3. ...

  2. 配置Jupyter Notebook

    配置Jupyter Notebook 1 修改Jupyter Notebook的工作目录 Jupyter默认打开的是用户目录,使用如下步骤自行修改: CMD生成Jupyter配置文件: (python ...

  3. Python geometry_msgs.msg.PoseStamped() Examples

    https://www.programcreek.com/python/example/70252/geometry_msgs.msg.PoseStampedhttps://programtalk.c ...

  4. P4410 [HNOI2009]无归岛

    P4410 [HNOI2009]无归岛 显然这还是一个仙人掌图 对于同一个岛上的任意两个生物,他们有且仅有一个公共朋友 要求求最大独立集,和树形dp一样,遇到环时单独提出来处理一下就好了 #inclu ...

  5. vue项目构建:vue-cli+webpack常用配置

    1,Webpack-dev-server的proxy用法:https://www.jianshu.com/p/f489e7764cb8 2,vue-cli3搭建项目之webpack配置:https:/ ...

  6. fcntl 函数

    设置文件的flags,阻塞设置成非阻塞,非阻塞设置成阻塞(这连个在server开发中可以封装为基本函数) 线程引入 pthread_self 和 pthread_equal 原因 ——解决不同平台的问 ...

  7. perl 语法速查 | 模块安装

    perl -MCPAN -e shell install Bio::SeqIO 或者直接perl -MCPAN -e 'install Excel::Writer::XLSX' 用cpan装不上,编译 ...

  8. LINUX增加SWAP分区---install_oracle

    我们都知道在安装Linux系统时在分区时可以分配swap分区,而系统安装后(在运行中)如何建立或调整swap分区呢?在装完Linux系统之后,建立Swap分区有两种方法.1.新建磁盘分区作为swap分 ...

  9. 项目中一次排序规则的改动,注意到js中map的遍历的顺序

    背景:项目需要对前端页面上某个插件的下拉选择项进行排序,需要按照配置的顺序显示. 首先调查后台,发现sql语句中已经添加order by.之后发现查询结果遍历后封装进HashMap,这里改为LinkH ...

  10. Angular 执行 css3 简单的动画

    <div class="content"> 内容区域 <button (click)="showAside()">弹出侧边栏</b ...