法一:

#include <time.h>
#include <stdio.h>
int main() {    
      time_t now;    
      struct tm *timenow;    
      time(&now);    
      timenow = localtime(&now);    
      printf(“%s”, asctime(timenow));    
      return 0;
}

法二:

#include <time.h>
#include <stdio.h>
int main() {   
    char timebuf[100];
    time_t t;
    time (&t);
    strftime(timebuf, sizeof(timebuf),
        “%Y 年 %m 月 %d 日 %H:%M:%S”, localtime(&t));  
    printf(“%sn”, timebuf);    
    return 0;
}

法三:

#include <time.h>
#include <stdio.h>
int main() {   
    time_t lt;   /*define a longint time varible*/
    lt=time(NULL);/*system time and date*/
    printf(ctime(&lt));   /*english format output*/

    printf(asctime(localtime(&lt)));/*tranfer to tm*/
    printf(asctime(gmtime(&lt)));   /*tranfer to Greenwich time*/ 
    return 0;
}

法四:

#include <time.h>
#include <stdio.h>
int main() {   
    time_t sec = time(NULL);
    struct tm t = *localtime(&sec);
    printf( “%02d:%02d:%02dn “, t.tm_hour, t.tm_min, t.tm_sec);
    return 0;
}

法五:

#include <time.h>
#include <stdio.h>
int main() {   
    struct tm *newtime;
    long ltime;
    time(&ltime); 
  /* Obtain coordinated universal time*/
    newtime = gmtime(&ltime);
    printf(“Coordinated universal time is %sn “, asctime(newtime));
    return 0;
}