C++ examples for Internationalization:Time
Command | Replaced By |
---|---|
%a | Abbreviated weekday name |
%A | Full weekday name |
%b | Abbreviated month name |
%B | Full month name |
%c | Standard date and time string |
%d | Day of month as a decimal (1-31) |
%H | Hour (0-23) |
%I | Hour (1-12) |
%j | Day of year as a decimal (1-366) |
%m | Month as decimal (1-12) |
%M | Minute as decimal (0-59) |
%p | Locale's equivalent of AM or PM |
%S | Second as decimal (0-61) |
%U | Week of year, Sunday being first day (0-53) |
%w | Weekday as a decimal (0-6, Sunday being 0) |
%W | Week of year, Monday being first day (0-53) |
%x | Standard date string |
%X | Standard time string |
%y | Year in decimal without century (0-99) |
%Y | Year including century as decimal |
%Z | Time zone name |
%% | The percent sign |
#include <iostream> #include <ctime> using namespace std; int main() {// w w w . ja v a 2 s . c o m char str[64]; // Get the current system time. time_t t = time(NULL); // Show standard time and date string. strftime(str, 64, "%c", localtime(&t)); cout << "Standard format: " << str << endl; // Show a custom time and date string. strftime(str, 64, "%A, %B %d %Y %I:%M %p", localtime(&t)); cout << "Custom format: " << str << endl; return 0; }