News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

A time & Date in VC2008

Started by herge, January 19, 2013, 10:04:46 AM

Previous topic - Next topic

herge


Hi C++  fans!


// GMT.cpp : Defines the entry point for the console application.
// Friday, January 18, 2013 3:55 PM
#include "stdafx.h"
// crt_gmtime.c
// compile with: /W3
// This program uses _gmtime64 to convert a long-
// integer representation of coordinated universal time
// to a structure named newtime, then uses asctime to
// convert this structure to an output string.
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
using std::cout;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{
   struct tm *newtime;
   struct tm today;
   __int64 ltime;
   char buff[128];
   errno_t err;
   _time64( &ltime );
   // Obtain coordinated universal time:
   newtime = _gmtime64( &ltime ); // C4996
   // Note: _gmtime64 is deprecated; consider using _gmtime64_s
   asctime_s( buff, sizeof(buff), newtime );
   int i;
   for ( i = 0; i < sizeof(buff); i++  )
   { // Remove line Feed with Space
   if( buff [ i ] == 10 ) buff [ i ] = 32;
   }
   cout << "Coordinated universal time is "
    << buff << "UTC"
        << endl;
   // Use time structure to build a customized time string.
    err = _localtime64_s( &today, &ltime );
    if (err)
    {
        cout << " _localtime64_s failed due to Bad arguments.";
        exit(1);
    }
   strftime( buff, 128,
         "Today is %A, day %d of %B in the year %Y.\n", &today );
   cout << buff;
   strftime( buff, sizeof(buff),"%#c %p %z", &today );
   cout << buff << endl;
   _getch(); // Wait!
   return 0;
}
/* expected output
Coordinated universal time is Fri Jan 18 22:00:58 2013 UTC
Today is Friday, day 18 of January in the year 2013.
Friday, January 18, 2013 17:00:58 PM EST
*/




I have Windows XP SP3

Regards Herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.


herge


Hi Vortex:

Yes it is C++ but C is quicker to type.

I prefer an old Borland compiler.

Regards Herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

Gunther

Hi herge,

and what is your question?

Gunther
You have to know the facts before you can distort them.

herge


Hi Gunther:

What's up?

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge

#5
 I have discovered if you go Microsoft with AOL 9
you get a lot of internet script errors. But if I use IE it works
well even with the reduced band width because
Aol has the connection.

Regards Herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge

Hi Everbody:

To get rid of specific warning in 2008 vc++ or 2005 vc++

1>c:\documents and settings\user\my documents\visual studio 2008\projects\gmt\gmt\gmt.cpp(25) : warning C4996: '_gmtime64': This function or variable may be unsafe. Consider using _gmtime64_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\time.h(209) : see declaration of '_gmtime64'

Project Properties
Configuration Properties
C/C++
Advanced
Disable Specific Warnings
4996
OK

You will find the
#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_DEPRECATE 1
#pragma warning( disable : 4996 )


Will not work!

Regards herge


Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

K_F

Deleted..
Hutch - I was replying to another post and it posted here !

This is with reference to the logging in - and posting problem I mentioned earlier :0
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'