Hello friends I want to create a digital clock in c.I am using this code #include<stdio.h> #include<time.h> #include<stdlib.h> #include<conio.h> void main() { clrscr(); time_t now; time(&now); printf("%s",ctime(&now)); getch(); } Code (markup): The result is Friday Jan 01 07:44:35 2010 I want to print each part seperately i.e I want to print the result like this Time: 07:44:35 Day: Friday Date: Jan 01 2010 How Can I do it?Plz somebody help
You may try this. time_t now; tm *t; time(&now); t = localtime(&now); Code (markup): struct tm is as follows. int tm_sec seconds [0,61] int tm_min minutes [0,59] int tm_hour hour [0,23] int tm_mday day of month [1,31] int tm_mon month of year [0,11] int tm_year years since 1900 int tm_wday day of week [0,6] (Sunday = 0) int tm_yday day of year [0,365] int tm_isdst daylight savings flag You could get each component as t->tm_hour, etc... Hope this helps.