|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
time function inC
hi!
i want to get the time and date as seperate stringd,,, the following cod e return me as a complete string,,,can anyone tell how can i gat them as 2 seperate strings /* localtime example */ #include <stdio.h> #include <time.h> int main () { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); printf ( "Current date and time are: %s", asctime (timeinfo) ); return 0; } Output: Current date and time are: Mon May 5 17:36:17 2003 |
|
#2
|
|||
|
|||
|
how to subtract minutes from time...in C
hi!
well i had been able to figure out how to get time and date... #include <time.h> #include <stdio.h> #define SIZE 256 int main (void) { char buffer1[SIZE]; char buffer2[SIZE]; time_t curtime; struct tm *loctime; /* Get the current time. */ curtime = time (NULL); /* Convert it to local time representation. */ loctime = localtime (&curtime); /* Print out the date and time in the standard format. */ fputs (asctime (loctime), stdout); /* Print it out in a nice format. */ strftime (buffer1, SIZE, " %x\n", loctime); printf("date: %s\n",buffer1); strftime (buffer2, SIZE, "%X", loctime); printf("time: %s\n",buffer2); return 0; } but now wat i want to do is subtract 5 minutes from the current time...and get the new time..in same format.. can anybody suggest how a can do this? regards ![]() |
|
#3
|
||||
|
||||
|
Re: how to subtract minutes from time...in C
Quote:
From the man page for the time function: Quote:
I've not tried it myself, but it seems that you should just need to subtract 300 (5min times 60sec/min) to change the time value to five minutes prior. E.g.: Code:
#include <time.h>
#include <stdio.h>
#define SIZE 256
int main (void)
{
char buffer1[SIZE];
char buffer2[SIZE];
time_t curtime;
struct tm *loctime;
time_t priortime;
struct tm *loctime_minus5;
/* Get the current time. */
curtime = time (NULL);
/* Convert it to local time representation. */
loctime = localtime (&curtime);
/* display loc time as before */
/* ... */
/* now do five minutes ago */
priortime = curtime - 300; /* to get time 5 minutes ago */
loctime_minus5 = localtime (&priortime);
/* display prior time the same way as you did curtime, */
/* except that you use loctime_minus5 */
/* ... */
return 0;
}
Last edited by dwise1_aol : May 5th, 2003 at 09:51 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > time function inC |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|