51使用sprintf函数时有字节对齐问题,ARM中则不存在。所以51中需注意格式:
char year,month,day;
sprintf(buf,"%lld-%lld-%lld",(Uint32)year,(Uint32)month,(Uint32)day); <span style="white-space:pre"> </span>对
sprintf(buf,"%02lld-%02lld-%02lld",(Uint32)year,(Uint32)month,(Uint32)day);<span style="white-space:pre"> </span>对
sprintf(buf,"%d-%d-%d",(Uint32)year,(Uint32)month,(Uint32)day); <span style="white-space:pre"> </span>错误
sprintf(buf,"%lld-%lld-%lld",year,month,day); <span style="white-space:pre"> </span>错误
本文探讨了在51单片机中使用sprintf函数进行日期格式化时遇到的字节对齐问题,并提供了正确的格式化字符串示例。通过对比正确与错误的用法,帮助读者理解如何在51单片机上正确地格式化日期。
1358

被折叠的 条评论
为什么被折叠?



