Hello:
After downloading a Help file for VC2010 C++ library
it was close to 168 MB and I have a slow modem so
it took about two days.
I had to play around with the Time Zone and reset the TZ
enviornment variable. We still need Dos.
/* GermTag.cpp : Defines the entry point for the console application.
// Sunday, August 23, 2015 12:38:30 PM
Author: Herge
Location: Waterloo, Ontario, CANADA*/
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <time.h>
#include <conio.h>
using std::cout;
using std::setw;
using std::setfill;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hStdout, hStdin;
WORD wOldColourAttrs;
char buf [ 128 ];
const char* MonthNum[ ] = {
"Zero","First","Second","Third","Fourth","Fifth","Sixth","Seventh",
"Eighth","Ninth","Tenth","Eleventh","Twelveth","Thirteenth",
"Fourteenth","Fifteenth","Sixteenth","Seventeenth",
"Eighteenth","Nineteenth","Twentyth","Twenty First",
"Twenty Second","Twenty Third","Twenty Fourth",
"Twenty Fifth","Twenty Sixth","Twenty Seventh",
"Twenty Eightth","Twenty Nineth","Thirty",
"Thirty First"};
const char* DayName [ ] = {
"Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday"};
const char* MonthNam[ ] = {
"January","February","March",
"April","May","June",
"July","August","September",
"October","November","December"};
hStdin = GetStdHandle(STD_INPUT_HANDLE);
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
{
MessageBox(NULL, TEXT("GetConsoleScreenBufferInfo"),
TEXT("Console Error"), MB_OK);
return 1;
}
wOldColourAttrs = csbiInfo.wAttributes; // save old colours
if (! SetConsoleTextAttribute(hStdout, 15))
{
MessageBox(NULL, TEXT("SetConsoleTextAttribute"),
TEXT("Console Error"), MB_OK);
return 1;
}
SetConsoleTextAttribute( GetStdHandle( STD_INPUT_HANDLE ), 15);
// 15 Bright White
struct tm newtime;
char am_pm [] = "AM";
__time64_t long_time;
time_t t;
t = time(0);
tm* P = localtime ( &t );
errno_t err;
// Get time as 64-bit integer.
_time64 ( &long_time );
err = _localtime64_s( &newtime, &long_time );
if (err)
{
printf("Invalid argument to _localtime64_s.");
exit(1);
}
if ( P-> tm_hour > 12 ) // Set up extension.
strcpy_s ( am_pm, sizeof ( am_pm ), "PM" );
if ( P-> tm_hour > 12 ) // Convert from 24-hour
P-> tm_hour -= 12; // to 12-hour clock.
if ( P-> tm_hour == 0 ) // Set hour to 12 if midnight.
P-> tm_hour = 12;
cout << setw(2) << setfill('0') << P-> tm_mon + 1 << "/"
<< setw(2) << P-> tm_mday << "/"
<< setw(2) << P-> tm_year % 100 << " ";
cout << setw(2) << P-> tm_hour << ":"
<< setw(2) << P-> tm_min << ":"
<< setw(2) << P-> tm_sec << " "
<< am_pm << endl;
if(P-> tm_isdst)
{
cout << "IS DAYLIGHT SAVINGS TIME YES " << endl;
}
else
{
cout << "IS STANDARD TIME YES " << endl;
}
if( _putenv_s( "TZ", "GST-2GDT" ) != 0 ) // Western Europe
// "TZ", "EST5EDT" for Eastern Standard i e New York City
// Note Negative offset are actual Postive i e Plus UTC + 2 for Germany
{
printf( "Unable to set TZ\n" );
exit( 1 );
}
else
{
_tzset();
int daylight;
_get_daylight( &daylight );
printf( "_daylight = %dH\n", daylight );
long timezone;
_get_timezone( &timezone );
printf( "_timezone = %ld\n", timezone );
printf( "_offset UTC = %1d\n", timezone/3600 );
size_t s;
char tzname[100];
_get_tzname( &s, tzname, sizeof(tzname), 0 );
printf( "_tzname[0] = %s\n", tzname );
}
cout << DayName[ P-> tm_wday ] << " "
<< MonthNum [P-> tm_mday]
<< " of " << MonthNam[ P-> tm_mon] << ", "
<< 1900 + P-> tm_year << " " << setw(2)
<< P-> tm_hour << ":" << setw(2) << P-> tm_min
<< ":" << setw(2) << P-> tm_sec
<< " " << am_pm << " " << tzname[0] << endl;
cout << " Day " << P-> tm_yday << " of "
<< 1900 + P-> tm_year << endl;
/*
>SET TZ=EST+5EDT
In a Dos Box i e Command Prompt set TZ to
your Time Zone. This is for Eastern Standard Time.
The %Z will Not work if TZ is not set before.
IE Toronto, New York City are in EST.
*/
strftime ( buf , sizeof(buf) , "%Z Time is ... %#c\n", localtime ( &t ) );
cout << buf;
strftime ( buf , sizeof(buf) , "%Z Time is ... %A, %B, %d , %Y %X %p\n", localtime ( &t ) );
cout << buf;
strftime ( buf , sizeof(buf) , "UTC Time is ... %a, %b, %d , %Y %X %p\n", gmtime ( &t ) );
cout << buf;
strftime ( buf , sizeof(buf) , "%Z Time is ... %p %H %M %S, %A, %b, %d , %Y %X %p\n", localtime ( &t ) );
cout << buf;
strftime ( buf , sizeof(buf) , "%Z Time is ... %x %X %p\n", localtime ( &t ) );
cout << buf;
strftime ( buf , sizeof(buf) , "%Z Time is ... %c %p\n", localtime ( &t ) );
cout << buf;
strftime ( buf , sizeof(buf) , "%A P-> tm_wday ", localtime ( &t ) );
cout << buf << P-> tm_wday;
SetConsoleTextAttribute(hStdout, wOldColourAttrs);// Restore Old Colour
cout << " \nPress Any Key ... \n";
_getch();
return 0;
}
Output will look this we hope.
08/23/15 01:30:08 AM
IS DAYLIGHT SAVINGS TIME YES
_daylight = 71H
_timezone = -3600
_offset UTC = -1
_tzname[0] = GST
Sunday Twenty Third of August, 2015 01:30:08 AM GST
Day 234 of 2015
GDT Time is ... Sunday, August 23, 2015 07:30:08
GDT Time is ... Sunday, August, 23 , 2015 07:30:08 AM
UTC Time is ... Sun, Aug, 23 , 2015 05:30:08 AM
GDT Time is ... AM 07 30 08, Sunday, Aug, 23 , 2015 07:30:08 AM
GDT Time is ... 08/23/15 07:30:08 AM
GDT Time is ... 08/23/15 07:30:08 AM
Sunday P-> tm_wday 0
Press Any Key ...
Edited we had Standard time not Summer Time so is -2 i e UTC+02.
Regards herge