size_t strftime(char* cpOutput, size_t qMaxSize, const char* kcpFormat, const tm* kqpTimePtr);
Format Table
Token | Substitution | Range | Example |
%a | Weekday (Abbreviated Name) | Sun, Mon, Tue, Wed, Thu, Fri, Sat | Mon |
%A | Weekday (Full Name) | Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday | Sunday |
%b | Month (Abbreviated Name) | Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec | Jan |
%B | Month (Full Name) | January, February, March, April, May, June, July, August, September, October, November, December | February |
%c | Date/Time Representation (Locale) | Any Date and Time | 10/10/18 08:19:38 |
%d | Day of Month | [01, 31] | 03 |
%H | Hour in 24 hour format | [00, 23] | 14 |
%I | Hour in 12 hour format | [00, 11] | 09 |
%j | Day of the year | [001, 366] | 034 |
%m | Month (as number) | [01, 12] | 04 |
%M | Minute | [00, 59] | 00 |
%p | Ante Meridiem or Post Meridiem | AM, PM | AM |
%S | Second | [00, 59] | 45 |
%U | Week (as number) Sunday Start | [00, 53] | 07 |
%w | Weekday (as number, 0 = Sunday) | [0, 6] | 5 |
%W | Week (as number) Monday Start | [00, 53] | 43 |
%x | Local Date Representation | Any Date | 10/10/18 |
%X | Local Time Representation | Any Time | 08:19:38 |
%y | Year Modulo 100 | [00, 99] | 24 |
%Y | Year | Any Year | 2008 |
%z | Time Zone (Locale) | Any Time Zone | Central Standard Time |
%Z | Time Zone (Locale) | Any Time Zone | Central Standard Time |
%% | Percent Sign | | |
%#c | Long Date/Time Representation (Locale) | Any Date and Time | Saturday, October 18, 2008 08:32:11 |
%#x | Long Date Representation (Locale) | Any Date | Saturday, October 18, 2008 |
%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y | Removes Leading Zeros | | |
%#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#% | Ignored | | |
#include <iostream> #include <ctime> int main() { using namespace std; time_t qTime; tm* qpTimeSpec; // Get the number of seconds since midnight Jan. 1, 1970 time(&qTime); // Convert the seconds to a tm struct variable qpTimeSpec = gmtime(&qTime); char caTime[100]; size_t qActualLength = strftime(caTime, 100, "%I:%M %p", qpTimeSpec); cout << "Written length = " << qActualLength << endl; cout << "Time = " << caTime << endl; return 0; }
© 20072024 XoaX.net LLC. All rights reserved.