// Append date time to log's filename // But only if logfile name ends in .TXT // So it is possible to restart a program many times a day // and not overwrite last times logging files void LogAnalysis::AppendDateTimeToFilename() { CString append; __timeb64 now; struct tm today; _ftime64_s(&now); _localtime64_s(&today,&now.time); append.Format("_%4.4d%2.2d%2.2d_%2.2d%2.2d%2.2d_%03d.txt" ,today.tm_year + 1900 ,today.tm_mon + 1 ,today.tm_mday ,today.tm_hour ,today.tm_min ,today.tm_sec ,now.millitm); // Finding the .txt extension CString file(m_logFileName); file.MakeLower(); int pos = file.Find(".txt"); if(pos > 0) { m_logFileName = m_logFileName.Left(pos); RemoveLastMonthsFiles(today); m_logFileName += append; } }
//-------------------------------------------------------------------------- HANDLE OpenPcapNgFile(const char *logDir, char *filename, const size_t len) { char timeStr[16]; __time64_t timestamp; struct tm localtime; char hostname[MAX_COMPUTERNAME_LENGTH+1]; DWORD hostnameLen = sizeof(hostname); HANDLE file = NULL; if (!GetComputerName(hostname, &hostnameLen)) { LogError("Cannot get hostname"); return INVALID_HANDLE_VALUE; } // Get time _time64(×tamp); _localtime64_s(&localtime, ×tamp); strftime(timeStr, sizeof(timeStr), "%Y%m%d_%H%M%S", &localtime); // Format log file name _snprintf_s(filename, len, len, "%s\\%s_%s.pcapng", logDir, hostname, timeStr); // Open file file = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); if (file == INVALID_HANDLE_VALUE) { LogError("Cannot open log file %s", filename); return INVALID_HANDLE_VALUE; } printf("Writing events to %s\n", filename); return file; }
void Log::logMessage(const String& message, LogMessageLevel lml) { if ((lml - mLogLevel) >= 0) { struct tm pTime; bool timeSet = false; if (mTimeStamp) { __time64_t long_time; _time64(&long_time); timeSet = _localtime64_s(&pTime, &long_time) == 0; } if (timeSet) { mLog << std::setw(2) << std::setfill('0') << pTime.tm_hour << ":" << std::setw(2) << std::setfill('0') << pTime.tm_min << ":" << std::setw(2) << std::setfill('0') << pTime.tm_sec << ": "; } mLog << message << std::endl; mLog.flush(); } }
std::string QuantixCamera::createFilePath() { std::string filePathStem = "\\\\epsrv1\\EP\\data\\"; std::string year; std::string month; std::string day; struct tm localTime; __int64 rawTime; errno_t err; _time64( &rawTime ); // Obtain coordinated universal time: err = _localtime64_s( &localTime, &rawTime ); if (err) { std::cerr << "Invalid Argument to _gmtime64_s." << std::endl; } year = STI::Utils::valueToString(localTime.tm_year + 1900); month = STI::Utils::valueToString(localTime.tm_mon + 1); day = STI::Utils::valueToString(localTime.tm_mday); return filePathStem + year + "\\" + month + "\\" + day + "\\data\\"; }
//----------------------------------------------------------------------------- // 取得星期 short C_NTime::Week() const { struct tm sTime; __int64 i64Sec = *this; return _localtime64_s(&sTime, &i64Sec) == 0 ? static_cast<short>(sTime.tm_wday) : -1; }
HRESULT GetLocalTime(char* localTime, size_t sizeInBytes) { HRESULT hr = E_FAIL; struct tm newtime; __int64 ltime; errno_t err; // Get time _time64( <ime ); // Obtain the coordinated universal time err = _localtime64_s( &newtime, <ime ); if (err) { wprintf(L"ERROR: Invalid argument to _localtime64_s."); } // Convert the universal time to an ASCII representation err = asctime_s(localTime, sizeInBytes, &newtime); if (err) { wprintf(L"ERROR: Converting time to a string failed.\n"); } else { wprintf(L"Local time is: %S", localTime); hr = S_OK; } return(hr); }
char* tr_getLogTimeStr( char * buf, int buflen ) { char tmp[64]; struct tm now_tm; struct timeval tv; time_t seconds; int milliseconds; gettimeofday( &tv, NULL ); #ifdef WIN32 { __time64_t long_time; errno_t err; // Get time as 64-bit integer. _time64( &long_time ); // Convert to local time. err = _localtime64_s( &now_tm, &long_time ); if (err) { printf("Invalid argument to _localtime64_s."); return buf; }; } #else seconds = tv.tv_sec; tr_localtime_r( &seconds, &now_tm ); #endif strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm ); milliseconds = tv.tv_usec / 1000; tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds ); return buf; }
errno_t __cdecl _tctime64_s ( _TSCHAR * buffer, size_t sizeInChars, const __time64_t *timp ) { struct tm tmtemp; errno_t e; _VALIDATE_RETURN_ERRCODE( ( ( buffer != NULL ) && ( sizeInChars > 0 ) ), EINVAL ) _RESET_STRING(buffer, sizeInChars); _VALIDATE_RETURN_ERRCODE( ( timp != NULL ), EINVAL ) _VALIDATE_RETURN_ERRCODE_NOEXC( ( *timp >= 0 ), EINVAL ) e = _localtime64_s(&tmtemp, timp); if ( e == 0 ) { e = _tasctime_s(buffer, sizeInChars, &tmtemp); } return e; }
static std::tm millisToLocal (int64 millis) noexcept { #if JUCE_WINDOWS && JUCE_MINGW time_t now = (time_t) (millis / 1000); return *localtime (&now); #elif JUCE_WINDOWS std::tm result; millis /= 1000; if (_localtime64_s (&result, &millis) != 0) zerostruct (result); return result; #else std::tm result; time_t now = (time_t) (millis / 1000); if (localtime_r (&now, &result) == nullptr) zerostruct (result); return result; #endif }
struct tm * evil_localtime_r(const time_t *timep, struct tm *result) { _localtime64_s(result, timep); return result; }
int writeToLog(string msg) { ofstream file; while (1) { try { struct tm newtime; char am_pm[] = "AM"; __time64_t long_time; char timebuf[26]; errno_t err; // Get time as 64-bit integer. _time64(&long_time); // Convert to local time. err = _localtime64_s(&newtime, &long_time); err = asctime_s(timebuf, 26, &newtime); string outputfile; outputfile = name; outputfile += "-output.txt"; file.open(outputfile.c_str() , ios::app); if (!file.is_open()) throw exception(); timebuf[strlen(timebuf) - 1] = '\0'; file << timebuf << ": " << msg << endl; file.close(); return 1; } catch(exception) {Sleep(100); } } return 0; }
void CGitPropertyPage::Time64ToTimeString(__time64_t time, TCHAR * buf, size_t buflen) const { struct tm newtime; SYSTEMTIME systime; LCID locale = LOCALE_USER_DEFAULT; if (!CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE)) locale = MAKELCID((WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)), SORT_DEFAULT); *buf = '\0'; if (time) { TCHAR timebuf[MAX_STRING_LENGTH] = { 0 }; TCHAR datebuf[MAX_STRING_LENGTH] = { 0 }; _localtime64_s(&newtime, &time); systime.wDay = (WORD)newtime.tm_mday; systime.wDayOfWeek = (WORD)newtime.tm_wday; systime.wHour = (WORD)newtime.tm_hour; systime.wMilliseconds = 0; systime.wMinute = (WORD)newtime.tm_min; systime.wMonth = (WORD)newtime.tm_mon+1; systime.wSecond = (WORD)newtime.tm_sec; systime.wYear = (WORD)newtime.tm_year+1900; if (CRegStdDWORD(_T("Software\\TortoiseGit\\LogDateFormat")) == 1) GetDateFormat(locale, DATE_SHORTDATE, &systime, NULL, datebuf, MAX_STRING_LENGTH); else GetDateFormat(locale, DATE_LONGDATE, &systime, NULL, datebuf, MAX_STRING_LENGTH); GetTimeFormat(locale, 0, &systime, NULL, timebuf, MAX_STRING_LENGTH); *buf = '\0'; _tcsncat_s(buf, buflen, datebuf, MAX_STRING_LENGTH-1); _tcsncat_s(buf, buflen, _T(" "), MAX_STRING_LENGTH-1); _tcsncat_s(buf, buflen, timebuf, MAX_STRING_LENGTH-1); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- char* formattedTime(const char* formatting, char* output) { struct tm* t; #ifdef _MSC_VER #if _MSC_VER >= 1400 struct tm time; errno_t tError; #endif #endif TimeType long_time; TimeFunc(&long_time); t = NULL; #ifdef _MSC_VER #if _MSC_VER < 1400 t = _localtime64(&long_time); #else t = &time; tError = _localtime64_s(&time, &long_time); #endif #else // Non windows platforms t = localtime(&long_time); #endif memset(output, 0, 128); snprintf(output, 128, formatting, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec ); return output; }
void Log::logMessage(const String& message, LogMessageLevel lml, bool maskDebug) { if ((mLogLevel + lml) >= 0) ///todo pomyœleæ nad tym { struct tm pTime; bool timeSet = false; if (mTimeStamp) { __time64_t long_time; _time64(&long_time); timeSet = _localtime64_s(&pTime, &long_time) == 0; } if (mDebugOut && !maskDebug) { #ifdef _WIN32 OutputDebugStringA(message.c_str()); OutputDebugStringA("\n"); #endif if (lml == LML_CRITICAL) { if (timeSet) { std::cerr << std::setw(2) << std::setfill('0') << pTime.tm_hour << ":" << std::setw(2) << std::setfill('0') << pTime.tm_min << ":" << std::setw(2) << std::setfill('0') << pTime.tm_sec << ": "; } std::cerr << message << std::endl; } else { if (timeSet) { std::cout << std::setw(2) << std::setfill('0') << pTime.tm_hour << ":" << std::setw(2) << std::setfill('0') << pTime.tm_min << ":" << std::setw(2) << std::setfill('0') << pTime.tm_sec << ": "; } std::cout << message << std::endl; } } // Write time into log if (!mSuppressFile) { if (timeSet) { mLog << std::setw(2) << std::setfill('0') << pTime.tm_hour << ":" << std::setw(2) << std::setfill('0') << pTime.tm_min << ":" << std::setw(2) << std::setfill('0') << pTime.tm_sec << ": "; } mLog << message << std::endl; mLog.flush(); } } }
/*! \brief The function returns the current time of day in ms since midnight \param date_ When not 0, the corresponding current date is put in here. \param secs_ When not 0, the full timestamp in seconds since the epoch is put in here. \returns The number of milliseconds that have passed since midnight. */ uint32_t XsTime_getTimeOfDay(struct tm* date_, time_t* secs_) { #ifdef _WIN32 // CORRECTION_DELTA_MS is the maximum allowed difference between the system time and the performance counter time. This depends on the granularity of the clocks. static const int64_t CORRECTION_DELTA_MS = 32; //! \todo This value was experimentally determined. 20 is too low. Find better solution static int64_t startTimePerfCount; static int64_t startTimeSysTime; static int64_t perfCountFreq = 0; int64_t t; LARGE_INTEGER pc; FILETIME now; __time64_t tin; GetSystemTimeAsFileTime(&now); t = (int64_t) (((((uint64_t) now.dwHighDateTime << 32) | now.dwLowDateTime)/10000) - 11644473600000); if (QueryPerformanceCounter(&pc)) { int64_t tNow; if (!perfCountFreq) { LARGE_INTEGER tmp; QueryPerformanceFrequency(&tmp); //lint !e534 the return value should match that of QueryPerformanceCounter above perfCountFreq = tmp.QuadPart; startTimePerfCount = pc.QuadPart; startTimeSysTime = t; } tNow = startTimeSysTime + (1000*(pc.QuadPart - startTimePerfCount))/perfCountFreq; if (t > tNow || (tNow-t) > CORRECTION_DELTA_MS) //!< \todo find better solution { startTimePerfCount = pc.QuadPart; startTimeSysTime = t; } else t = tNow; } tin = t/1000; if (date_ != NULL) _localtime64_s(date_,&tin); //lint !e534 if (secs_ != NULL) *secs_ = (time_t) tin; return (uint32_t) (t % (XsTime_secPerDay.m_msTime*1000)); //lint !e571 cast is ok #else struct timespec tp; clock_gettime(CLOCK_REALTIME, &tp); // compile with -lrt if (date_ != NULL) localtime_r(&tp.tv_sec,date_); if (secs_ != NULL) secs_[0] = tp.tv_sec; // 86400 = 24*60*60 = secs in a day, this gives us the seconds since midnight return (1000 * (tp.tv_sec % XsTime_secPerDay.m_msTime)) + (tp.tv_nsec/1000000); #endif }
struct tm * evil_localtime_r(const time_t *timep, struct tm *result) { __time64_t t = *timep; _localtime64_s(result, &t); return result; }
/// <summary> /// Helper function to retrieve the local current time /// </summary> inline PWCHAR GetLocalCurrentTime(PWCHAR buffer, UINT length) { __time64_t currentTime = _time64(nullptr); tm localTime; _localtime64_s(&localTime, ¤tTime); wcsftime(buffer, length, L"%#I:%M %p", &localTime); return buffer; }
void ThreadSafeLogError(const char * msg, int err) { char buf[200]; struct _timeb tv; struct tm tm; _ftime(&tv); _localtime64_s(&tm, &tv.time); strftime(buf, 80, "%H:%M:%S", &tm); sprintf(buf+strlen(buf), ".%03d %.100s: %d\n", tv.millitm, msg, err); OutputDebugString(buf); }
string getTimeString() { char timebuf[26]; time_t ltime; struct tm gmt; time(<ime); _localtime64_s(&gmt, <ime); asctime_s(timebuf, 26, &gmt); timebuf[24] = '\0'; // remove newline return string(timebuf); }
void MCS_getlocaldatetime(MCDateTime& r_datetime) { __time64_t t_time; _time64(&t_time); struct tm t_tm; _localtime64_s(&t_tm, &t_time); tm_to_datetime(true, t_tm, r_datetime); }
struct tm DateTime::ToLocalTm() const { __time64_t t = ShrinkToTimeT(time_.time_value); struct tm local_time; if (_localtime64_s(&local_time, &t)) { throw std::invalid_argument("failed to convert to local time"); } return local_time; }
tm GetLocalTime() { __time64_t Time; tm TimeStruct; _tzset(); // Apply environment variables so that _localtime_s will convert // properly _time64(&Time); _localtime64_s(&TimeStruct, &Time); return TimeStruct; }
void cBinaryFile::CreateTimestamp() { #ifdef WIN32 char buffer[32]; time_t ltime; time(<ime); struct tm now; _localtime64_s(&now, <ime); strftime(buffer, 32, "[%H:%M:%S] ", &now); int l_iLength = (int)strlen(buffer); NvFWrite( buffer, sizeof(char),l_iLength, m_pFile ); #endif //WIN32 }
string getString() { const int timeBufferLen = 1024; char timestr[timeBufferLen]; char buffer[timeBufferLen]; struct tm t; _localtime64_s(&t, &time_.time); std::strftime(timestr, timeBufferLen, "%Y.%m.%d %H:%M:%S", &t); _snprintf_s(buffer, timeBufferLen, "%s.%d", timestr, time_.millitm); return buffer; }
__time32_t NXtimet64to32(__time64_t t64) { tm t; _localtime64_s(&t, &t64); // ERR __time32_t r = _mktime32(&t); if(r == -1) { R(-1, "mktime error"); return _time32(NULL); } return r; }
/*! \brief A platform-independent clock. */ uint32_t getTimeOfDay(tm* date_, time_t* secs_) { #ifdef _WIN32 static int64_t startTimePerfCount; static int64_t startTimeSysTime; static int64_t perfCountFreq = 0; FILETIME now; GetSystemTimeAsFileTime(&now); int64_t t = (int64_t) (((((uint64_t) now.dwHighDateTime << 32) | now.dwLowDateTime)/10000) - 11644473600000); LARGE_INTEGER pc; if (QueryPerformanceCounter(&pc)) { if (!perfCountFreq) { LARGE_INTEGER tmp; QueryPerformanceFrequency(&tmp); perfCountFreq = tmp.QuadPart; startTimePerfCount = pc.QuadPart; startTimeSysTime = t; } int64_t tNow = startTimeSysTime + (1000*(pc.QuadPart - startTimePerfCount))/perfCountFreq; if (t > tNow || (tNow-t) > 16) { startTimePerfCount = pc.QuadPart; startTimeSysTime = t; } else t = tNow; } __time64_t tin = t/1000; if (date_ != NULL) _localtime64_s(date_,&tin); if (secs_ != NULL) *secs_ = (time_t) tin; return (uint32_t) (t % (XSENS_SEC_PER_DAY*1000)); #else timespec tp; clock_gettime(CLOCK_REALTIME, &tp); // compile with -lrt if (date_ != NULL) localtime_r(&tp.tv_sec,date_); if (secs_ != NULL) secs_[0] = tp.tv_sec; // 86400 = 24*60*60 = secs in a day, this gives us the seconds since midnight return (1000 * (tp.tv_sec % XSENS_SEC_PER_DAY)) + (tp.tv_nsec/1000000); #endif }
bool LeakReport::EnsureLeakReportFile() { AutoCriticalSection autocs(&s_cs); if (openReportFileFailed) { return false; } if (file != nullptr) { return true; } char16 const * filename = Js::Configuration::Global.flags.LeakReport; char16 const * openMode = _u("w+"); char16 defaultFilename[_MAX_PATH]; if (filename == nullptr) { // xplat-todo: Implement swprintf_s in the PAL #ifdef _MSC_VER swprintf_s(defaultFilename, _u("jsleakreport-%u.txt"), ::GetCurrentProcessId()); #else _snwprintf(defaultFilename, _countof(defaultFilename), _u("jsleakreport-%u.txt"), ::GetCurrentProcessId()); #endif filename = defaultFilename; openMode = _u("a+"); // append mode } if (_wfopen_s(&file, filename, openMode) != 0) { openReportFileFailed = true; return false; } Print(_u("================================================================================\n")); Print(_u("Chakra Leak Report - PID: %d\n"), ::GetCurrentProcessId()); struct tm local_time; uint64 time_ms = (uint64) PlatformAgnostic::DateTime::HiResTimer::GetSystemTime(); // utc #ifdef _MSC_VER __time64_t time_sec = time_ms / 1000; // get rid of the milliseconds _localtime64_s(&local_time, &time_sec); #else time_t time_sec = time_ms / 1000; // get rid of the milliseconds localtime_r(&time_sec, &local_time); #endif Print(_u("%04d-%02d-%02d %02d:%02d:%02d.%03d\n"), local_time.tm_year + 1900, local_time.tm_mon + 1, local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, time_ms % 1000); return true; }
// // Get a readable string from a __time64_t date // BOOL GitWCRev::CopyDateToString(WCHAR* destbuf, int buflen, __time64_t ttime) { const int min_buflen = 32; if (!destbuf || (min_buflen > buflen)) return FALSE; struct tm newtime; if (_localtime64_s(&newtime, &ttime)) return FALSE; // Format the date/time in international format as yyyy/mm/dd hh:mm:ss swprintf_s(destbuf, min_buflen, L"%04d/%02d/%02d %02d:%02d:%02d", newtime.tm_year + 1900, newtime.tm_mon + 1, newtime.tm_mday, newtime.tm_hour, newtime.tm_min, newtime.tm_sec); return TRUE; }
std::string MATLABPLOTTER::createFilename() { // creates a date & time stamped data file std::string filename; struct tm newtime; __int64 local_time; char time_buf[26]; errno_t err; _time64( &local_time ); // Obtain coordinated universal time: err = _localtime64_s( &newtime, &local_time ); if (err) { printf("Invalid Argument to _gmtime64_s."); } // Convert to an ASCII representation err = asctime_s(time_buf, 26, &newtime); if (err) { printf("Invalid Argument to asctime_s."); } std::string date_string = time_buf; size_t found; found=date_string.find_first_of(":"); while (found!=std::string::npos) { date_string[found]='_'; found=date_string.find_first_of(":",found+1); } found=date_string.find_first_of("\n"); while (found!=std::string::npos) { date_string.erase(found, 1); found=date_string.find_first_of("\n",found+1); } filename = "thermocouple data on " + date_string + ".csv"; return filename; }
//----------------------------------------------------------------------------- C_NTime::C_NTime(IN __int64 second) : m_wYear(0), m_wMon(0), m_wDay(0), m_wHour(0), m_wMin(0), m_wSec(0) { struct tm sTime; if(_localtime64_s(&sTime, &second) == 0) { m_wYear = static_cast<short>(sTime.tm_year + 1900); m_wMon = static_cast<short>(sTime.tm_mon + 1); m_wDay = static_cast<short>(sTime.tm_mday); m_wHour = static_cast<short>(sTime.tm_hour); m_wMin = static_cast<short>(sTime.tm_min); m_wSec = static_cast<short>(sTime.tm_sec); }//if }