Question? Show Time and Date in c program (NOT C++)

Question??? Show Time and Date in c program (NOT C++)

Page 1 of 1

2 Replies - 4348 Views - Last Post: 29 September 2009 - 08:01 AM Rate Topic: -----

#1 lowilliam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-September 09

Question? Show Time and Date in c program (NOT C++)

Posted 29 September 2009 - 03:37 AM

 #include <stdio.h>
 main(void)
 {
	 char updated_date[10];updated_time[10];
	 FILE *fp;

	 fp=fopen("test.txt","w");
	 fprintf(fp,"A_B_C_D_E_F_G_");
	 printf("Updated at: %s(%s)",updated_date,updated_time);
	 //I want to show the updated time and date
	 
 }

I want to show the updated time and date
what should I do?
could u give me an example

This post has been edited by lowilliam: 29 September 2009 - 03:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Question? Show Time and Date in c program (NOT C++)

#2 Ancient Dragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: Question? Show Time and Date in c program (NOT C++)

Posted 29 September 2009 - 06:00 AM

You will have to get the time/date from the operating system. Use the functions in time.h to do that. First call time() to get current time/date in seconds, then call localtime() to convert it to a tm structure. With that structure you can use sprintf() to format the date and time any way you want it, or you can call strftime() to format it.
Was This Post Helpful? 0
  • +
  • -

#3 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Question? Show Time and Date in c program (NOT C++)

Posted 29 September 2009 - 08:01 AM

The following example can be found here:
http://www.nextdawn....e-and-date-in-c

//An example of ctime() use:
#include <time.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
	time_t mytime;
	mytime = time(NULL);
	printf(ctime(&mytime));
getchar();
return 0;
}

This post has been edited by OliveOyl3471: 29 September 2009 - 08:01 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1