想玩个rtc时间显示,在格式化时间时用了sprintf函数,最后出来的结果一直不对,请教下是哪里的问题。
uchar t=0;
char time_display[30],time_display_hour[2],time_display_min[2],time_display_sec[2];
if(t!=calendar.sec)
{
t=calendar.sec;
if(calendar.hour<=9)
{
sprintf (time_display_hour,"0%d",calendar.hour);
}
else
{
sprintf (time_display_hour,"%d",calendar.hour);
}
if(calendar.min<=9)
{
sprintf (time_display_min,"0%d",calendar.min);
}
else
{
sprintf (time_display_min,"%d",calendar.min);
}
if(calendar.sec<=9)
{
sprintf (time_display_sec,"0%d",calendar.sec);
}
else
{
sprintf (time_display_sec,"%d",calendar.sec);
}
sprintf (time_display,"%d:%d:%d",time_display_hour,time_display_min,time_display_sec);
display_GB2312_string(1,1,time_display);
|