GoHacking.com: Ethical Hacking and Cyber Security
Home » C PROGRAMMING

C Program to Get the Current System Time

Submitted by on Wednesday, 16 January 20082 Comments

This program reads the current system time and displays it in the form HH:MM:SS

#include <stdio.h>
#include <dos.h>

int main(void)
{
struct time t;
gettime(&t);
printf(“The current time is: %2d:%02d:%02d\n”, t.ti_hour, t.ti_min, t.ti_sec);
return 0;
}



By using/following this site you agree to our Legal Disclaimer

2 Comments »

  • suneel said:

    hi

    this program can’t be run on linux as you are using dos.h,
    i want a program with same output with date (day month year separately).

    awaiting your response,

    bye.

  • Rohit Reddy said:

    program that prints the time is
    void main()
    {
    int hr,min,sec;
    for(hr=0;hr<24;hr++);
    {
    for(min=0;min<60;min++);
    {
    for(sec=0;sec<60;sec++);
    {
    sleep(1);
    clrscr();
    printf("%d%d%d",hr,min,sec);
    }
    }
    }
    }

    here "sleep(1)" command maintain interval of 1 sec between two print statements.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.