C语言 - 获取系统时间 以年月日时分秒的形式输出
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语言 - 获取系统时间 以年月日时分秒的形式输出的更多相关文章
- js获取当前时间的年月日时分秒以及时间的格式化
1.获取当前时间 var myDate = new Date(); 2.获取时间中的年月日时分秒 myDate.getYear(); // 获取当前年份(2位) myDate.getFullYear( ...
- java 获取当前时间及年月日时分秒
java代码如下: package test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.ut ...
- [SoapUI] 获取当前时间包括年月日时分秒来作为命名
import java.text.SimpleDateFormat GregorianCalendar calendar = new GregorianCalendar() def dateForma ...
- 在vue项目中显示实时时间(年月日时分秒)
1.在data中定义一个变量,存储时间 data(){ return { nowTime:'' } }, 2.给定一个div <div>{{nowTime}}</div> 3. ...
- Linux C 语言 获取系统时间信息
比如获取当前年份: /* 获取当前系统时间 暂时不使用 int iyear = 0; int sysyear = 0; time_t now; ...
- C语言 获取系统时间与睡眠时间函数
摘要: 以ms为单位,获取系统时间.睡眠或延迟时间函数的使用方法. #include<stdio.h> #include <time.h> #include <sys/t ...
- js 获取系统时间:年月日 星期 时分秒(动态)
最近再写一个纯html页面,有时间和天气的数据,天气后台给接口,时间要自己获取,我就自己弄了下, <div class="basic"></div> 这是放 ...
- c#.net 获取时间日期年月日时分秒格式
今天写代码发现两个比较不错的分享下:1.DateTime.ParseExact很多时候我们获取的时间是数字形式表示的,好比20140127134015.927856,通过这个方法DateTime.Pa ...
- c#.net 获取时间日期年月日时分秒生成自动文件名格式
下面是日期和时间的各种方法,转换为字符串. 如果把输出的格式改下就可以做类似的文件名了,例如:2016010110101224356.doc c#用DateTime.Now.ToString(&qu ...
随机推荐
- 如何在一个function里面设置一个全局的变量?
答:解决方法是在function的开始插入一个global声明: def f() global x
- Spring Cloud Gateway(六):路由谓词工厂 RoutePredicateFactory
本文基于 spring cloud gateway 2.0.1 1.简介 Spring Cloud Gateway 创建 Route 对象时, 使用 RoutePredicateFactory 创建 ...
- openfoam变热物性参数的设置【转载】
转载自:http://blog.sina.com.cn/s/blog_9de422500102va73.html 物性参数在constant/thermophysicalProperties文件中设置 ...
- C#读写三菱PLC数据 使用TCP/IP 协议
本文将使用一个Github开源的组件库技术来读写三菱PLC和西门子plc数据,使用的是基于以太网的TCP/IP实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能 ...
- Linux中显示系统中USB信息的lsusb命令
来源:Linux中国 原文:https://linux.cn/article-2448-1.html 通用串行总线(USB)被设计成为连接计算机外设的标准,如键盘.鼠标.打印机.数码相机.便携式媒体 ...
- Linux | Vim使用
Linux vi/vim 所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在. 但是目前我们使用比较多的是 vim 编辑器. vim 具有程序编辑的能力,可以主 ...
- ubuntu16上启用外部管理端口
docker启动外部访问端口在Ubuntu上: [root@maintance systemd] $cd /lib/systemd/system/ [root@maintance system] $c ...
- keras损失函数
keras文档: http://keras.io/objectives/ mean_squared_error / mse 均方误差,常用的目标函数,公式为((y_pred-y_true)**2) ...
- PorterDuffXfermode之Mode.SRC_IN
package com.loaderman.customviewdemo.view; import android.content.Context; import android.graphics.B ...
- java 获取String中的数字
随便给你一个含有数字的字符串,比如: String s="eert343dfg56756dtry66fggg89dfgf"; 那我们如何把其中的数字提取出来呢?大致有以下几种方法, ...