Author Topic: A time & Date in VC2008  (Read 5015 times)

herge

  • Member
  • ***
  • Posts: 480
A time & Date in VC2008
« on: January 19, 2013, 10:04:46 AM »

 Hi C++  fans!

Code: [Select]
// 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
« Last Edit: January 20, 2013, 12:31:43 AM by herge »
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

Vortex

  • Member
  • *****
  • Posts: 1704
Re: A time & Date in VC2008
« Reply #1 on: January 19, 2013, 07:46:53 PM »
Hi herge,

Hi C fans!

You posted C++ code.

herge

  • Member
  • ***
  • Posts: 480
Re: A time & Date in VC2008
« Reply #2 on: January 19, 2013, 08:01:08 PM »

 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

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: A time & Date in VC2008
« Reply #3 on: January 19, 2013, 11:51:22 PM »
Hi herge,

and what is your question?

Gunther
Get your facts first, and then you can distort them.

herge

  • Member
  • ***
  • Posts: 480
Re: A time & Date in VC2008
« Reply #4 on: January 20, 2013, 12:25:18 AM »

Hi Gunther:

 What's up?

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

herge

  • Member
  • ***
  • Posts: 480
Re: A time & Date in VC2008
« Reply #5 on: January 20, 2013, 01:15:31 AM »
 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
« Last Edit: January 20, 2013, 08:00:05 PM by herge »
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge

  • Member
  • ***
  • Posts: 480
Re: A time & Date in VC2008
« Reply #6 on: January 21, 2013, 01:28:29 AM »
Hi Everbody:

To get rid of specific warning in 2008 vc++ or 2005 vc++
Code: [Select]
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

  • Member
  • *****
  • Posts: 1287
  • Anybody out there?
Re: A time & Date in VC2008
« Reply #7 on: March 10, 2013, 02:24:03 AM »
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....'