Copy Date/Time to Windows Clipboard with C++

December 20, 2010 at 12:44 (c++, windows)

I was unable to find a suitable program to quickly generate a timestamp in the format I desired, so I decided to write one using C++, specifically MinGW’s g++ v4.5.0 along with <windows.h>. This is my first real experience with Windows-specific programming other than a few hello worlds, so it was instructive as well as frustrating. It took considerable time to discover and familiarise myself with SetClipboardData(). Eventually I was able to modify the code in this thread (which didn’t compile as-is) and obtain a working clipboard prototype very similar to this, which I didn’t find until afterward. After that, it was mainly a matter of understanding the functions in <ctime>.

The format I was after is this:

2010-12-20 07:44:19 UTC-5

However, the code can of course be easily modified for various other formats. Here is the code:

Read the rest of this entry »


Permalink Leave a Comment