C-Program to set current date

C, C++, etc Programing examples. Post as many you can. Test the programs and discuss about the output of the programes.
Forum rules
Please Discuss & post only about the programes and its Output

C-Program to set current date

Postby Piya » Fri Apr 24, 2009 12:09 pm

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
struct date d;
clrscr();
getdate(&d);
printf("The current date is %d /%d / %d\n",d.da_day,d.da_mon,d.da_year);
getch();
User avatar
Piya
Super Member
Super Member
 
Posts: 9
Joined: Thu Apr 16, 2009 3:46 pm
membership: Senior Technician of The Institution of Engineers (India)- ST

ad
 

Re: C++-Program to find current date and time

Postby praveen » Fri Apr 24, 2009 12:37 pm

Using ctime().

1: #include <time.h>
2: #include <iostream.h>
3:
4: int main()
5: {
6: time_t currentTime;
7:
8: // get and print the current time
9: time (&currentTime); // fill now with the current time
10: cout << "It is now " << ctime(&currentTime) << endl;
11:
12: struct tm * ptm= localtime(&currentTime);
13:
14: cout << "Today is " << ((ptm->tm_mon)+1) << "/";
15: cout << ptm->tm_mday << "/";
16: cout << ptm->tm_year << endl;
17:
18: cout << "\nDone.";
19: return 0;
20: }
Output: It is now Mon Mar 31 13:50:10 1997



check it out... this is the very useful link for C programing..
http://www.cs.utah.edu/dept/old/texinfo ... y_toc.html
Regards,
Praveen
AMIE Study

ImageImage
-------------------------------------------------------------------------------------------
Work from Home | AMIE Online Coaching
User avatar
praveen
Site Admin
 
Posts: 989
Joined: Thu Oct 23, 2008 1:42 pm
Location: Mumbai
membership: Senior Technician of The Institution of Engineers (India)- ST


Return to Computer Notes : Some Sample Programs

Who is online

Users browsing this forum: No registered users and 0 guests