Dave's Brain

Browse - Programming Tips - How can I make a timestamp on Windows?

Date: 2014sep26
Level: beginner
OS: Windows
Platform: win32
Language: C/C++

Q.  How can I make a timestamp on Windows?

A.  Use GetLocalTime() like this:

LPCSTR TimeStamp(LPSTR buf, const size_t size) { SYSTEMTIME now; GetLocalTime(&now); _snprintf_s(buf, size, _TRUNCATE, "%04d.%02d.%02d %02d:%02d:%02d" , now.wYear, now.wMonth, now.wDay , now.wHour, now.wMinute, now.wSecond); return buf; }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.