Can someone help me with this program.I had found that the output of this program should be the local time and display time and date and i dont know where my program gone wrong and display like this
time is 03:29:30

how to eliminate 1 from my should be "date 08/06/08"..please help me..


int main(void)
    struct tm *systime;
    time_t t;
    systime = localtime(&t);
    printf("time is %.2d:%.2d:%.2d\n",systime->tm_hour,systime->tm_min,systime->tm_sec);
    return 0;

Recommended Answers

All 2 Replies

Look up the specification of localtime(). My recollection is that systime->tm_year would be the number of years since 1900. 2008-1900, last I checked, yielded a value of 108.

>how to eliminate 1 from my should be "date 08/06/08"..please help me..

These values returned to the variable t are not quite ready to show in prime time yet.
They are correct but some need to be formatted to show like you want.
Functions like asctime() or ctime() can return a string in a predetermined format.
To display the date in the specific way you asked, the function strftime() can do it, counting that you pass to it the right arguments, that you set a correct size buffer to receive the string, and assuming you give it the right format place holders.

char buffer[9]; /* enough to contain the string "mm/dd/yy" plus '\0' */
if ( strftime(buffer, sizeof(buffer), "%m/%d/%y", systime) ) {
    printf("date %s\n", buffer);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.