c_cpp 将Date转换为char数组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 将Date转换为char数组相关的知识,希望对你有一定的参考价值。

char buff[100];
    if(ptm->tm_mon < 10){
            if(ptm->tm_mday < 10){
                    sprintf(buff,"%u-0%u-0%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
            }else{
                    sprintf(buff,"%u-0%u%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
            }
    }else{
            if(ptm->tm_mday < 10){
                    sprintf(buff,"%u-%u-0%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
            }else{
                    sprintf(buff,"%u-%u-%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
            }
    }

以上是关于c_cpp 将Date转换为char数组的主要内容,如果未能解决你的问题,请参考以下文章

如何将char数组转换为CString

将所有选定的列转换为_char

Oracle date、char、number处理转换(转)

如何将字符串数组转换为 Char * 数组 c++

SQL to_char,to_date日期字符串转换问题

将 char 2d 数组转换为 2d char 数组列表时出现问题