/*************************************************************************
> 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