Is there a simple way to just be able to add milliseconds to my timestamp function?

char stamp[100];
	time_t mytime;
	struct tm *mytm;
	mytime=time(NULL);
	mytm=localtime(&mytime);

	strftime(stamp,sizeof stamp,"%a, %d %b %Y %H:%M:%S %z",mytm);

	printf("%s\n" , stamp);

time.h does not support milliseconds, it is a C legacy library made for systems that "in general" cannot support more than seconds precision. Of course, modern computers do support milliseconds, and most often microseconds too. If your code is C, I believe there is no way. If in C++, there are OS specific calls (like posix time), but I recommend this Boost::date_time library, because it supports microseconds (or at least emulates it if the computer doesn't support it) and is not OS specific.

okay I'll look through that, thanks. and it is C++ I'm running Windows Vista I think it's 32 bit too if that makes any difference. I'm really not sure, just came into work saw a new machine one day and they added Vista to it.

Posix time looks like it has what I need, I'll give it a shot and check back if I run into some problems

well POSIX is not really for windows, I think there are some libraries to sort-of make it work, but Windows is not POSIX compliant (POSIX is essentially all operating systems except windows, see this wiki)

okay so I'm not sure if that will work since I'm not able to download anything on these computers. In order for any of that code to work I have to download the Boost library right?

Is there anything from Visual C++ library that will work?


**edit**
just read your post, guess that doesn't matter anyway.

Edited 6 Years Ago by wesduncan: n/a

I've been there, just so much information I couldn't find a simple answer so decided to ask here.
But thanks for trying.

This article has been dead for over six months. Start a new discussion instead.