diff options
author | Marshall Clow <marshall@idio.com> | 2013-07-01 16:53:14 +0000 |
---|---|---|
committer | Marshall Clow <marshall@idio.com> | 2013-07-01 16:53:14 +0000 |
commit | b6009a89491183910053baa9020cda9cc6cd3b42 (patch) | |
tree | d2d634c9bfd37013d3a964204d37774f4db36a3a /tools/release/strftime.cpp | |
parent | 976548a67dbaa0ded32850cfec396d19877b9d72 (diff) | |
parent | 7b8f9263e91a8036235f672800965914d5f1edb4 (diff) | |
download | boost-1.54.0.tar.gz |
Release 1.54.0boost-1.54.0
[SVN r84923]
Diffstat (limited to 'tools/release/strftime.cpp')
-rw-r--r-- | tools/release/strftime.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/release/strftime.cpp b/tools/release/strftime.cpp new file mode 100644 index 0000000000..57d66099ae --- /dev/null +++ b/tools/release/strftime.cpp @@ -0,0 +1,68 @@ +// Command line utility to output the date under control of a format string + +// Copyright 2008 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#define _CRT_SECURE_NO_WARNINGS + +#include <ctime> +#include <string> +#include <iostream> +#include <cstdlib> + +using namespace std; + +int main(int argc, char * argv[]) +{ + if (argc != 2 ) + { + cerr << + "Invoke: strftime format\n" + "Example: strftime \"The date is %Y-%m-%d in ISO format\"" + "The format codes are:\n" + " %a Abbreviated weekday name\n" + " %A Full weekday name\n" + " %b Abbreviated month name\n" + " %B Full month name\n" + " %c Date and time representation appropriate for locale\n" + " %d Day of month as decimal number (01 - 31)\n" + " %H Hour in 24-hour format (00 - 23)\n" + " %I Hour in 12-hour format (01 - 12)\n" + " %j Day of year as decimal number (001 - 366)\n" + " %m Month as decimal number (01 - 12)\n" + " %M Minute as decimal number (00 - 59)\n" + " %p Current locale's A.M./P.M. indicator for 12-hour clock\n" + " %S Second as decimal number (00 - 59)\n" + " %U Week of year as decimal number, with Sunday as first day of week (00 - 53)\n" + " %w Weekday as decimal number (0 - 6; Sunday is 0)\n" + " %W Week of year as decimal number, with Monday as first day of week (00 - 53)\n" + " %x Date representation for current locale\n" + " %X Time representation for current locale\n" + " %y Year without century, as decimal number (00 - 99)\n" + " %Y Year with century, as decimal number\n" + " %z, %Z Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown\n" + " %% Percent sign\n" + ; + return 1; + } + + string format = argv[1]; + time_t t = time(0); + tm * tod = localtime(&t); + if (!tod) + { + cerr << "error: localtime function failed\n"; + return 1; + } + char* s = new char [format.size() + 256]; + if (strftime( s, format.size() + 256, format.c_str(), tod ) == 0 ) + { + cerr << "error: buffer overflow\n"; + return 1; + } + + cout << s; + return 0; +} |