470,849 Members | 1,600 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

How to determine curreent date and time/

I am using GCC on FEDORA.

I want to print current date an time. How can do that.

Thanks
-Sanchit
Jun 27 '08 #1
6 4246
On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.

I want to print current date an time. How can do that.
system("date");

Jun 27 '08 #2
On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.
I want to print current date an time. How can do that.

system("date");
Oh I forgot to mention.. I want a C function for this.
Jun 27 '08 #3
On 14 Apr 2008 at 17:39, Sanchit wrote:
On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam.invalidwrote:
>On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.
I want to print current date an time. How can do that.

system("date");

Oh I forgot to mention.. I want a C function for this.
strftime?

Jun 27 '08 #4
On 14 Apr, 19:14, Sanchit <sanchitgupt...@gmail.comwrote:
I am using GCC on FEDORA.

I want to print current date an time. How can do that.
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main(){

time_t now = time(NULL);
struct tm *now_s = localtime(&now);

if(now_s == NULL)
return EXIT_FAILURE;

printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+now_s->tm_year, ++now_s -
>tm_mon,
now_s->tm_mday, now_s->tm_hour, now_s->tm_min,now_s->tm_sec);

return EXIT_SUCCESS;
}

Bye.
Jun 27 '08 #5
>I am using GCC on FEDORA.
>
I want to print current date an time. How can do that.
In C, time() gets you the current date/time in a time_t format.
Various functions can get that into a printable string format:

ctime()
localtime() followed by strftime()
localtime() followed by asctime()
Jun 27 '08 #6
On Apr 14, 10:39 pm, Sanchit <sanchitgupt...@gmail.comwrote:
On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.
I want to print current date an time. How can do that.
system("date");

Oh I forgot to mention.. I want a C function for this.
http://www.cs.utah.edu/dept/old/texi...19.html#SEC320
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Gord | last post: by
1 post views Thread by John Feeley | last post: by
3 posts views Thread by Manny Chohan | last post: by
21 posts views Thread by rdemyan via AccessMonster.com | last post: by
7 posts views Thread by wanwan | last post: by
4 posts views Thread by Matt.Russett | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.