Home > Software engineering >  There is no confessed, about a localtime
There is no confessed, about a localtime

Time:09-16

Development environment vc2013, I have a write database functions, requires repeated to write time data into the database, written in the others c file time_util. C, with function USES the localtime in this file, the original is:
Time_t timeT=(time_t) second;
* struct tm ptime.
Ptime=localtime (& amp; TimeT);
Cycle run, as written, the program is easy to collapse, the reason is ptime sometimes often return NULL;
Online to find, may be a localtime function problem, hence to
Time_t timeT=(time_t) second;
Struct tm ptime.
Localtime_s (& amp; Ptime, & amp; TimeT);

Compilation is LNK2028 LNK2019 and LNK1120 error
Error 8 error LNK2028: cannot resolve the tag (0 a00000f) "extern" C "int __cdecl localtime_s (const struct tm * and __int64 const * const)" (? Localtime_s @ @ $$J0YAHQAUtm @ @ QB_J @ Z), the tag in the function "extern" C "void __cdecl unix_to_date (unsigned __int64, char *)" (? Unix_to_date @ @ $$J0YAX_KPAD @ Z) referenced in the D: \ are testing test \ \ stage MultiProbesMFCApping leica (0807) after the success of the database to modify \ MFCApp \ time_util obj MFCApp
Error error of 9 LNK2019: cannot resolve the external symbol "extern" C "int __cdecl localtime_s (* const struct tm, __int64 const * const)" (? Localtime_s @ @ $$J0YAHQAUtm @ @ QB_J @ Z), the symbol in the function "extern" C "void __cdecl unix_to_date (unsigned __int64, char *)" (? Unix_to_date @ @ $$J0YAX_KPAD @ Z) referenced in the D: \ are testing test \ \ stage MultiProbesMFCApping leica (0807) after the success of the database to modify \ MFCApp \ time_util obj MFCApp

You really can't find the reason, o great god help see

CodePudding user response:

https://zh.cppreference.com/w/c/chrono/localtime

CodePudding user response:

 
//crt_localtime_s c
/* This program USES _time64 to get the current time
* and then USES _localtime64_s () to convert this time to a structure
* representing the local time. The program converts the result
* from a 24 - hour clock to a 12 - hour clock and determines the
* the proper extension (AM/PM).
*/

#include
#include
#include

Int main (void)
{
Newtime struct tm;
Char am_pm []="AM";
__time64_t long_time;
Char timebuf [26].
Errno_t err;

//Get the time as the 64 - bit integer.
_time64 (& amp; Long_time);
//Convert to local time.
Err=_localtime64_s (& amp; Newtime, & amp; Long_time);
If (err)
{
Printf (" Invalid argument to _localtime64_s. ");
exit(1);
}
If (newtime. Tm_hour & gt; 12)//Set up the extension.
Strcpy_s (am_pm, sizeof (am_pm), "PM");
If (newtime. Tm_hour & gt; 12)//Convert the from 24 - hour
Newtime. Tm_hour -=12;//to 12 - hour clock.
If (newtime. Tm_hour==0)/Set/hour to 12 if midnight.
Newtime. Tm_hour=12;

//Convert to an ASCII representation.
Err=asctime_s (timebuf, 26, & amp; Newtime);
If (err)
{
Printf (" Invalid argument to asctime_s. ");
exit(1);
}
Printf (" %. 19 s % s \ n ", timebuf, am_pm);
}



CodePudding user response:


C functions multithreaded unsafe, database time now () built-in function not directly use?

CodePudding user response:

The Windows API GetLocalTime directly

CodePudding user response:

Localtime_s code is open, if can't find the libraries, copy the code to write a

CodePudding user response:

Localtime_s, _localtime32_s, _localtime64_s & lt; Time. H> The or & lt; Time. H>

CodePudding user response:

Direct database level can solve, used to set the field to a datetime, defaults to getdate () can, need not insert the fields, as long as the write data is automatically added time, similar to other databases,
  • Related