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. Python的is和==

    is是对比地址:==是对比值

  2. 针对于linux初学者的学习(摘自网络端)

    一. 选择适合自己的Linux发行版谈到linux的发行版本,太多了,可能谁也不能给出一个准确的数字,但是有一点是可以肯定的,linux正在变得越来越流行, 面对这么多的Linux 发行版,打算从其他 ...

  3. Struts2 入门笔记

    一.介绍 1.Struts网站 https://struts.apache.org/ struts 是通过基于请求响应模式的应用framework 1) 控制器(Controller)--控制整个Fr ...

  4. 寻找丢失的微服务-HAProxy热加载问题的发现与分析 原创: 单既喜 一点大数据技术团队 4月8日 在一点资讯的容器计算平台中,我们通过HAProxy进行Marathon服务发现。本文记录HAProxy服务热加载后某微服务50%概率失效的问题。设计3组对比实验,验证了陈旧配置的HAProxy在Reload时没有退出进而导致微服务丢失,并给出了解决方案. Keywords:HAProxy热加

    寻找丢失的微服务-HAProxy热加载问题的发现与分析 原创: 单既喜 一点大数据技术团队 4月8日 在一点资讯的容器计算平台中,我们通过HAProxy进行Marathon服务发现.本文记录HAPro ...

  5. c++ 套接字 --->2002 java NIO --->netty

    c++ 套接字 --->2002 java NIO --->netty

  6. SpringBoot视图层技术

    一.SpringBoot整合jsp 在maven的dependencies的依赖中除了springBoot启动器还要添加对jstl和jsp的依赖. <dependencies> <d ...

  7. 【转载】 迁移学习简介(tranfer learning)

    原文地址: https://blog.csdn.net/qq_33414271/article/details/78756366 土豆洋芋山药蛋 --------------------------- ...

  8. pytorch中的学习率调整函数

    参考:https://pytorch.org/docs/master/optim.html#how-to-adjust-learning-rate torch.optim.lr_scheduler提供 ...

  9. linux cheese摄像机工具在window电脑上显示

    1.SSH Secure Shell Client 2.Xming 实现步骤: 1.运行Xming工具 2.运行SSH Secure Shell Client,登陆linux系统 输入命令:expor ...

  10. osgViewer::View::setUpViewOnSingleScreen()

    void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...