current date

P

placid

how would i get the current date in the format of DD/MM/YYYY, do i use
functions in time.h and how would i compile it (linking) ?
 
W

Walter Roberson

how would i get the current date in the format of DD/MM/YYYY, do i use
functions in time.h

Yes, use time() to fetch the current time, localtime() to break
it down into a struct tm, then extract the structure members of that
that you are interested in and print them yourself.

Caution: the tm_year field is "years since 1900", so be sure to
add 1900 to the value before trying to print it as YYYY !!
and how would i compile it (linking) ?

No special compilation / linking requirements: use whatever
method is appropriate to your system to compile and link C programs.
 
P

placid

Walter said:
Yes, use time() to fetch the current time, localtime() to break
it down into a struct tm, then extract the structure members of that
that you are interested in and print them yourself.

Caution: the tm_year field is "years since 1900", so be sure to
add 1900 to the value before trying to print it as YYYY !!


No special compilation / linking requirements: use whatever
method is appropriate to your system to compile and link C programs.
-- Ann Landers


Thanks man, got it working man
 
M

Michael Wojcik

Yes, use time() to fetch the current time, localtime() to break
it down into a struct tm, then extract the structure members of that
that you are interested in and print them yourself.

Or use strftime:

#include <time.h>
#include <stdio.h>
int main(void)
{
time_t Now = time(NULL);
struct tm Date = *localtime(&Now);
char DateBuf[12];

strftime(DateBuf, sizeof DateBuf, "%d/%m/%Y", &Date);
puts(DateBuf);
return 0;
}

That's what strftime is for.

--
Michael Wojcik (e-mail address removed)

Even if Jesus set up a blogging cafe in the center of Rockport, Texas
and extolled the virtues of a woman's right to choose while snapping
pictures of gay weddings with his Nokia, it would have made no
difference to this election. -- Ashlee Vance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top