Hi,
I suggest you could try the following code:
#include<iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
int main() {
time_t timetoday;
time(&timetoday);
cout << "Calendar date and time as per todays is : " << asctime(localtime(&timetoday));
return 0;
}
I get error that The variable or function maybe unsafe and I thingk it is there for a reason.
According to your description, is the error you encountered is "C4996"? I suggest you could try to add the following code:
#pragma warning(disable : 4996)
For more details I suggest you could refer to the Doc:
And you could also try to use asctime_s and localtime_s:
#include <time.h>
#include <stdio.h>
struct tm newtime;
__time32_t aclock;
int main( void )
{
char buffer[32];
errno_t errNum;
_time32( &aclock );
_localtime32_s( &newtime, &aclock );
errNum = asctime_s(buffer, 32, &newtime);
printf( "Current date and time: %s", buffer );
return 0;
}
Best Regards,
Jeanine
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.