473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how to put date and time in c

Hi Guys..

i was wondering if any of you have tryed to put date and time on c programming? as i trying to get it.. seems doesnt work.. does any1 here have a code for it?
thanks
Mar 12 '07 #1
3 2883
horace1
1,510 Expert 1GB
Hi Guys..

i was wondering if any of you have tryed to put date and time on c programming? as i trying to get it.. seems doesnt work.. does any1 here have a code for it?
thanks
post you code and we can try to help!
Mar 12 '07 #2
post you code and we can try to help!
here is my coding.. at the end of the program you will see a code of timestamp()
dont know if that is rite or wrong.

void heading(char *string);
void centreline(char *string);
void gcls(void) ;
void gsolidrectangle(int x1, int y1, int x2, int y2,int col);
void timestamp(void);

//mouse int function
int GetX(void);
int GetY(void);
int GetKey(void);
void ShowCursor(void);
void HideCursor(void);
int ButtonStatus(void);
void SetMouseMode(int);
void PrintMousePosition(void);
void UpdateMousePosition(void);
void PrintMouseButtonStatus(void);
void UpdateMouseButtonStatus(void);
void CheckMouseButtonStatus(void);
void DrawOneButton(void);
void OnButtonClick(void);
void LabelButtons(void);
void RelabelButtons(int);
void About(void);
void InitializeMouse(void);
void Startup(void);
void LoadOne(void);
void RestrictMouse(int,int,int,int);


// cpu register structure for dos function calls.
struct REGPACK reg;
union REGS regs;


//Mouse function coding here..

int GetX(void)
{
// get mouse X position
reg.r_ax=3;
intr(51,&reg);
return(reg.r_cx);
}

int GetY(void)
{
// get mouse Y position
reg.r_ax=3;
intr(51,&reg);
return(reg.r_dx);
}


void ShowCursor(void)
{
// Turn on mouse cursor
reg.r_ax=1;
intr(51,&reg);
}

void HideCursor(void)
{
// Turn off mouse cursor.
reg.r_ax=2;
intr(51,&reg);
}

void RestrictMouse(int x1,int y1,int x2,int y2)
{
union REGS i,o;
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);

i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}
void getmousepos(int *button,int *x,int *y)
{
char *ss;
union REGS i,o;
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

void CheckMouseButtonStatus(void)
{
// gets mouse buttons pressed.

/* status=ButtonStatus();

LeftButton=0;
RightButton=0;
MiddleButton=0;

if(status==1){LeftButton=1;}
if(status==2){RightButton=1;}
if(status==3){LeftButton=1;RightButton=1;}
if(status==4){MiddleButton=1;}
if(status==5){LeftButton=1;MiddleButton=1;}
if(status==6){LeftButton=1;MiddleButton=1;}
if(status==7){LeftButton=1;RightButton=1;MiddleBut ton=1;}*/
}












int main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode,button=1,x,y;

/* initialize graphics mode */
initgraph(&gdriver, &gmode, "c:\\turboc");

/* read result of initialization */
errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}

/* do some graphics */
//Heading



//green background
gsolidrectangle(640,570,0,0,deepcyan );
//text
setcolor(black);
moveto(515,130);
outtext("Control Panel");
setcolor(black);
rectangle(500,150,620,350);
rectangle(510,160,610,180);//screen
gsolidrectangle(510,160,610,180,cyan); //colour screen
//1st row button
rectangle(515,210,540,190);
rectangle(572,210,545,190);
rectangle(605,210,581,190);
moveto(525,200);
outtext("1"); //text keypad 1
moveto(555,200);
outtext("2"); //text keypad 2
moveto(590,200);
outtext("3"); //text keypad 3

//2nd row button
rectangle(515,220,540,243);
rectangle(572,220,545,243);
rectangle(580,220,605,243);
moveto(525,230);
outtext("4"); //text keypad 4
moveto(555,230);
outtext("5"); //text keypad 5
moveto(590,230);
outtext("6"); //text keypad 6

//3rd row button
rectangle(540,275,515,250);
rectangle(574,275,545,250);
rectangle(605,275,580,250);
moveto(525,260);
outtext("7"); //text keypad 7
moveto(555,260);
outtext("8"); //text keypad 8
moveto(590,260);
outtext("9"); //text keypad 9

//4th row button
rectangle(540,305,515,279);
rectangle(574,305,545,280);
rectangle(605,305,580,280);
moveto(525,290);
outtext("*"); //text keypad *
moveto(555,290);
outtext("0"); //text keypad 0
moveto(590,290);
outtext("#"); //text keypad #


//background of rectangle
gsolidrectangle(10,100,100,120,cyan);
gsolidrectangle(10,140,100,160,green);
gsolidrectangle(10,180,100,200,yellow);
gsolidrectangle(10,220,100,240,deepmagenta);
gsolidrectangle(10,260,100,280,deepgreen);
gsolidrectangle(10,300,100,320,cyan);

setcolor(deepblue);
rectangle(10,100,100,120);
rectangle(10,140,100,160);
rectangle(10,180,100,200);
rectangle(10,220,100,240);
rectangle(10,260,100,280);
rectangle(10,300,100,320);

//switch box

moveto(390,130);
outtext("Switch Box");
setcolor(black);
rectangle(490,350,350,150);
gsolidrectangle(450,160,485,190,red);//sw switch select
circle(468,175,10);
moveto(355,170);
outtext("SW Select");
//bit0 switch
gsolidrectangle(450,220,485,195,red);//bit0 switch
circle(468,207,10);
moveto(360,205);
outtext("Bit-0");
//bit1 switch
gsolidrectangle(450,250,485,225,red);//bit1 switch select
circle(468,237,10);
moveto(360,235);
outtext("Bit-1");
//bit2 switch
gsolidrectangle(450,280,485,255,red);//bit2 switch
circle(468,267,10);
moveto(360,265);
outtext("Bit-2");
gsolidrectangle(450,310,485,285,red);//bit2 switch
circle(468,297,10);
moveto(360,295);
outtext("Bit-3");

//middle button for sw swtich
circle(468,175,5);
moveto(355,170);
//middle button for bit-0
circle(468,207,5);
moveto(360,205);
//middle button for bit-1
circle(468,237,5);
moveto(360,235);
//middle button for bit-2
circle(468,267,5);
moveto(360,265);
//middle button for bit-3
circle(468,297,5);
moveto(360,295);

//Instruction box
rectangle(345,450,620,360);
moveto(360,370);
outtext("1 - Press S Start Motor");
moveto(360,390);
outtext("2 - Press T stop motor");
moveto(360,410);
outtext("3 - Press O Heater on");
moveto(360,430);
outtext("4 - Press 1 Heater off");

//Temperature box
rectangle(350,80,620,110);
gsolidrectangle(480,85,580,100,red);
moveto(360,90);
outtext("Temperature:");

//ON and OFF Switches
rectangle(350,60,620,10);
moveto(360,20);
outtext("Switches ON/OFF");
circle(361,40,5);
moveto(370,40);
outtext("ON");
circle(420,40,5);
moveto(430,40);
outtext("OFF");

//restart button
circle(500,40,5);
moveto(510,40);
outtext("Restart");

//Exit Button
rectangle(48,428,123,398);
gsolidrectangle(50,425,120,400,red);
moveto(70,410);
outtext("EXIT");


ShowCursor();
RestrictMouse(0,0,getmaxx(),getmaxy());
//mouse position for exit button to exit

while(!kbhit())
{
getmousepos(&button,&x,&y);
if((button&1)==1)
{
getmousepos(&button,&x,&y);
if(x>=70 && x<=100 && y>=410 && y<=420)
exit(0);
}
}

//showing time and date

void timestamp()
{
time_t ltime; /* calendar time */
ltime=time(NULL); /* get current cal time */
printf("%s",asctime( localtime(&ltime) ) );
}
Mar 12 '07 #3
chella
51
Hi Guys..

i was wondering if any of you have tryed to put date and time on c programming? as i trying to get it.. seems doesnt work.. does any1 here have a code for it?
thanks

Hi Bhavesh,
Here is a sample code which will give you the current date and time.


#include<time.h>

int main(){
struct tm *tm;
time_t curtime;
char *ntm;

curtime = time(NULL);

tm = localtime(&curtime);
ntm = asctime(tm);

printf("Time = %s\n",ntm);
return 0;
}

Hope Ur problem is solved...

Regards,
chella
Mar 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
3
by: colleen1980 | last post by:
Hi: Data in my table is in that format. How to i separate date with time. 11/9/2006 10:10:46 AM Thank You.
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
4
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.