linux 获取当前日期与时间

linux 获取当前日期与时间

/* ************************************************************************
 *       Filename:  main.c
 *    Description:  
 *        Version:  1.0
 *        Created:  2012年06月19日 10时34分55秒
 *       Revision:  none
 *       Compiler:  gcc
 *         Author:  YOUR NAME (), 
 *        Company:  
 * ************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(int argc, char *argv[])
{

    struct timeval tv;
    char mytime[20] = "";

    gettimeofday(&tv,NULL);
    strftime(mytime,sizeof(mytime),"%Y-%m-%d %T",localtime(&tv.tv_sec));

    printf("Time:%s\n",mytime);

    return 0;

}
posted @ 2012-06-19 10:48  hnrainll  阅读(5619)  评论(0编辑  收藏  举报