Linux 获取当前时间BCD

/*************************************************************************
  > File Name: char.cpp
  > Author: yuhuqiao
  > Mail: yuhuqiao@163.com 
  > Created Time: 2019年01月09日 星期三 13时40分41秒
 ************************************************************************/

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

long get_time()
{
	time_t now_time;
	now_time = time(NULL);
	struct tm *ptr;
	char str[20];
	strftime(str,sizeof(str),"%Y%m%d%H%M%S",localtime(&now_time));
	cout << "str : "<< str <<endl;
	return atol(str);
	
}




int DectoBCD(long Dec, unsigned char *Bcd, int length)  
{

	int i;  
	int temp;  
	for (i = length - 1; i >= 0; i--)  
	{  
		temp = Dec % 100;  
		Bcd[i] = ((temp / 10) << 4) + ((temp % 10) & 0x0F);  
		Dec /= 100;  
	}  
	return 0;  
}  


int main()
{
	long t = get_time();
	unsigned char tmp[7];
	DectoBCD(t,tmp,7);
	for(int i=0; i<7; i++)
	{
		printf("0x%02X\n",tmp[i]);
	}
}

 

str : 20190109174620
0x20
0x19
0x01
0x09
0x17
0x46
0x20

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值