渔舟唱晚的天空
——welkinwalker的遐想
linux 中与标准库的strftime相对的有一个strptime的函数,这个函数可以用来解析log文件中的时间字符串,例子:
#include<time.h>
#include
<iostream>

using namespace std;

int main() {
    tm tm; 
    
char buf[255];

    strptime(
"24/Aug/2011:09:42:35""%d/%b/%Y:%H:%M:%S" , &tm);
//  strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
    strftime(buf, sizeof(buf), "%d %b %Y %H:%M"&tm);
    puts(buf);
    
return 0;

} 

 

posted on 2011-08-24 11:17  welkinwalker  阅读(3413)  评论(0编辑  收藏  举报