timestamp milliseconds

Hello,

I want to write a timestamp function that returns time in the following format. e.g. Sat May 20 2000 15:21:51:202

The code fragment:
1
2
3
4
5
6
7
8
 
void timestamp() {
			time_t tv;
			timeval tval;
			tv = time(0);
			tval = localtime(&tv);

			unsigned int t = (time.tv_sec * 1000) + (time.tv_usec / 1000);


error: no match for call to '(timeval) (int)'
error: no match for 'operator=' in 'tval = localtime(((const time_t*)(& tv)))'

if I use gettimeofday(&time, NULL); is error: 'gettimeofday' was not declared in this scope.

thanks for the help,
looks like you are missing some includes..
not exact to your format but might get you started.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>      // Needed for printf()
#include <time.h>       // Needed for time data structures and functions
using namespace std;


int main()
{
  time_t timer;                // Define the timer
  struct tm *tblock;           // Define a structure for time block

  // Get time of day
  timer = time(NULL);

  // Converts date/time to a structure
  tblock = localtime(&timer);

  // Output ASCII data/time
  printf("Local time is: %s", asctime(tblock));

}
Topic archived. No new replies allowed.