int futime(int fd, struct utimbuf *times) { struct tm *tmb; SYSTEMTIME systemTime; FILETIME localFileTime; FILETIME lastWriteTime; FILETIME lastAccessTime; struct utimbuf deftimes; if (times == NULL) { time(&deftimes.modtime); deftimes.actime = deftimes.modtime; times = &deftimes; } if ((tmb = localtime(×->modtime)) == NULL) { errno = EINVAL; return (-1); } systemTime.wYear = (WORD) (tmb->tm_year + 1900); systemTime.wMonth = (WORD) (tmb->tm_mon + 1); systemTime.wDay = (WORD) (tmb->tm_mday); systemTime.wHour = (WORD) (tmb->tm_hour); systemTime.wMinute = (WORD) (tmb->tm_min); systemTime.wSecond = (WORD) (tmb->tm_sec); systemTime.wMilliseconds = 0; if (!SystemTimeToFileTime(&systemTime, &localFileTime) || !LocalFileTimeToFileTime(&localFileTime, &lastWriteTime)) { errno = EINVAL; return(-1); } if ((tmb = localtime(×->actime)) == NULL) { errno = EINVAL; return (-1); } systemTime.wYear = (WORD) (tmb->tm_year + 1900); systemTime.wMonth = (WORD) (tmb->tm_mon + 1); systemTime.wDay = (WORD) (tmb->tm_mday); systemTime.wHour = (WORD) (tmb->tm_hour); systemTime.wMinute = (WORD) (tmb->tm_min); systemTime.wSecond = (WORD) (tmb->tm_sec); systemTime.wMilliseconds = 0; if (!SystemTimeToFileTime(&systemTime, &localFileTime) || !LocalFileTimeToFileTime(&localFileTime, &lastAccessTime)) { errno = EINVAL; return(-1); } if (!SetFileTime(_fdtab[fd].hnd, NULL, &lastAccessTime, &lastWriteTime)) { errno = EINVAL; return(-1); } return (0); }
void AFX_CDECL AfxTimeToFileTime(const CTime& time, LPFILETIME pFileTime) { ASSERT(pFileTime != NULL); if (pFileTime == NULL) { AfxThrowInvalidArgException(); } SYSTEMTIME sysTime; sysTime.wYear = (WORD)time.GetYear(); sysTime.wMonth = (WORD)time.GetMonth(); sysTime.wDay = (WORD)time.GetDay(); sysTime.wHour = (WORD)time.GetHour(); sysTime.wMinute = (WORD)time.GetMinute(); sysTime.wSecond = (WORD)time.GetSecond(); sysTime.wMilliseconds = 0; // convert system time to local file time FILETIME localTime; if (!SystemTimeToFileTime((LPSYSTEMTIME)&sysTime, &localTime)) CFileException::ThrowOsError((LONG)::GetLastError()); // convert local file time to UTC file time if (!LocalFileTimeToFileTime(&localTime, pFileTime)) CFileException::ThrowOsError((LONG)::GetLastError()); }
bool CArchiverUNARJ::InspectArchiveGetWriteTime(FILETIME &FileTime) { if(!m_hInspectArchive){ ASSERT(!"Open an Archive First!!!\n"); return false; } //拡張版関数で時刻取得 if(ArchiverGetWriteTimeEx){ FILETIME TempTime; if(!ArchiverGetWriteTimeEx(m_hInspectArchive,&TempTime))return false; if(!LocalFileTimeToFileTime(&TempTime,&FileTime))return false; return true; } //通常版関数で時刻取得 else if(ArchiverGetWriteTime){ DWORD UnixTime=ArchiverGetWriteTime(m_hInspectArchive); if(-1==UnixTime){ return false; } //time_tからFileTimeへ変換 LONGLONG ll = Int32x32To64(UnixTime, 10000000) + 116444736000000000; FileTime.dwLowDateTime = (DWORD) ll; FileTime.dwHighDateTime = (DWORD)(ll >>32); return true; } else{
/* change_file_date : change the date/time of a file filename : the filename of the file where date/time must be modified dosdate : the new date at the MSDos format (4 bytes) tmu_date : the SAME new date at the tm_unz format */ void ChangeFileDate( const char *filename, uLong dosdate, tm_unz tmu_date ) { #ifdef WIN32 HANDLE hFile; FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING,0,NULL); GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); LocalFileTimeToFileTime(&ftLocal,&ftm); SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); CloseHandle(hFile); #else struct utimbuf ut; struct tm newdate; newdate.tm_sec = tmu_date.tm_sec; newdate.tm_min=tmu_date.tm_min; newdate.tm_hour=tmu_date.tm_hour; newdate.tm_mday=tmu_date.tm_mday; newdate.tm_mon=tmu_date.tm_mon; if (tmu_date.tm_year > 1900) newdate.tm_year=tmu_date.tm_year - 1900; else newdate.tm_year=tmu_date.tm_year ; newdate.tm_isdst=-1; ut.actime=ut.modtime=mktime(&newdate); utime(filename,&ut); #endif }
/* change_file_date : change the date/time of a file filename : the filename of the file where date/time must be modified dosdate : the new date at the MSDos format (4 bytes) tmu_date : the SAME new date at the tm_unz format */ void change_file_date(const char *filename,uLong dosdate,tm_unz tmu_date) { #ifdef WIN32 HANDLE hFile; FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING,0,NULL); GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); LocalFileTimeToFileTime(&ftLocal,&ftm); SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); CloseHandle(hFile); #elif defined (unix) || defined (__TURBOC__) || defined (_MSV_VER) || defined (__WATCOMC__) struct utimbuf ut; struct tm newdate; newdate.tm_sec = tmu_date.tm_sec; newdate.tm_min=tmu_date.tm_min; newdate.tm_hour=tmu_date.tm_hour; newdate.tm_mday=tmu_date.tm_mday; newdate.tm_mon=tmu_date.tm_mon; if (tmu_date.tm_year > 1900) newdate.tm_year=tmu_date.tm_year - 1900; else newdate.tm_year=tmu_date.tm_year ; newdate.tm_isdst=-1; ut.actime=ut.modtime=mktime(&newdate); utime(filename,&ut); #else #error No implementation defined to set file date #endif }
void __FromDOSDT( unsigned short d, unsigned short t, FILETIME *NT_stamp ) { FILETIME local_ft; DosDateTimeToFileTime( d, t, &local_ft ); LocalFileTimeToFileTime( &local_ft, NT_stamp ); }
TimeValue System::LocalToUTCTime( TimeValue iLocalTime, TimeUnit iResolution, const TimeZone * pTimeZone ) const { FILETIME hFlatTimeLocal; _RevertTimeValue( &hFlatTimeLocal, iLocalTime, iResolution ); if ( pTimeZone == NULL ) { FILETIME hFlatTimeUTC; BOOL bRes = LocalFileTimeToFileTime( &hFlatTimeLocal, &hFlatTimeUTC ); DebugAssert( bRes != FALSE ); return _ConvertTimeValue( &hFlatTimeUTC, iResolution ); } else { TIME_ZONE_INFORMATION hTimeZone; _RevertTimeZone( &hTimeZone, pTimeZone ); SYSTEMTIME hSystemTimeLocal; BOOL bRes = FileTimeToSystemTime( &hFlatTimeLocal, &hSystemTimeLocal ); DebugAssert( bRes != FALSE ); SYSTEMTIME hSystemTimeUTC; bRes = TzSpecificLocalTimeToSystemTime( &hTimeZone, &hSystemTimeLocal, &hSystemTimeUTC ); DebugAssert( bRes != FALSE ); FILETIME hFlatTimeUTC; bRes = SystemTimeToFileTime( &hSystemTimeUTC, &hFlatTimeUTC ); DebugAssert( bRes != FALSE ); return _ConvertTimeValue( &hFlatTimeUTC, iResolution ); } }
FileTime TimeToFileTime(Time time) { #ifdef PLATFORM_WIN32 SYSTEMTIME tm; Zero(tm); tm.wYear = time.year; tm.wMonth = time.month; tm.wDay = time.day; tm.wHour = time.hour; tm.wMinute = time.minute; tm.wSecond = time.second; FileTime ftl, ftg; SystemTimeToFileTime(&tm, &ftl); LocalFileTimeToFileTime(&ftl, &ftg); return ftg; #endif #ifdef PLATFORM_POSIX struct tm t; t.tm_sec = time.second; t.tm_min = time.minute; t.tm_hour = time.hour; t.tm_mday = time.day; t.tm_mon = time.month - 1; t.tm_year = time.year - 1900; return mktime(&t); #endif }
int __stdcall RarArchive::pGetArchiveItem ( ArchiveItemInfo *pItem ) { RARHeaderDataEx *fileHeader = (RARHeaderDataEx *)malloc (sizeof(RARHeaderDataEx)); int nResult = m_pModule->m_pfnReadHeaderEx (m_hArchive, fileHeader); if ( !nResult ) { memset (pItem, 0, sizeof (PluginPanelItem)); strcpy ((char*)pItem->pi.FindData.cFileName, fileHeader->FileName); pItem->pi.FindData.dwFileAttributes = (BYTE)(fileHeader->FileAttr >> 16); //бред! if ( (fileHeader->Flags & 0x04) == 0x04 ) pItem->dwFlags |= AIF_CRYPTED; FILETIME lFileTime; DosDateTimeToFileTime (HIWORD(fileHeader->FileTime), LOWORD(fileHeader->FileTime), &lFileTime); LocalFileTimeToFileTime (&lFileTime, &pItem->pi.FindData.ftLastWriteTime); pItem->pi.FindData.nFileSizeHigh = fileHeader->UnpSizeHigh; pItem->pi.FindData.nFileSizeLow = fileHeader->UnpSize; m_pModule->m_pfnProcessFile (m_hArchive, RAR_SKIP, NULL, NULL); free(fileHeader); return E_SUCCESS; }
unsigned _RTL_FUNC _dos_setftime(int fd, unsigned date, unsigned time) { FILETIME timex,timet ; DosDateTimeToFileTime(date,time,&timex) ; LocalFileTimeToFileTime(&timex,&timet); return (!SetFileTime((HANDLE)fd,0,0,&timet)); }
static time_t filetime_dt( FILETIME t_utc ) { static int calc_time_diff = 1; static double time_diff; if ( calc_time_diff ) { struct tm t0_; FILETIME f0_local; FILETIME f0_; SYSTEMTIME s0_; GetSystemTime( &s0_ ); t0_.tm_year = s0_.wYear-1900; t0_.tm_mon = s0_.wMonth-1; t0_.tm_wday = s0_.wDayOfWeek; t0_.tm_mday = s0_.wDay; t0_.tm_hour = s0_.wHour; t0_.tm_min = s0_.wMinute; t0_.tm_sec = s0_.wSecond; t0_.tm_isdst = 0; SystemTimeToFileTime( &s0_, &f0_local ); LocalFileTimeToFileTime( &f0_local, &f0_ ); time_diff = filetime_seconds( f0_ ) - (double)mktime( &t0_ ); calc_time_diff = 0; } return ceil( filetime_seconds( t_utc ) - time_diff ); }
void cnv_tar2win_time(time_t tartime, FILETIME *ftm) { #ifdef HAS_LIBC_CAL_FUNCS FILETIME ftLocal; SYSTEMTIME st; struct tm localt; localt = *localtime(&tartime); st.wYear = (WORD)localt.tm_year+1900; st.wMonth = (WORD)localt.tm_mon+1; /* 1 based, not 0 based */ st.wDayOfWeek = (WORD)localt.tm_wday; st.wDay = (WORD)localt.tm_mday; st.wHour = (WORD)localt.tm_hour; st.wMinute = (WORD)localt.tm_min; st.wSecond = (WORD)localt.tm_sec; st.wMilliseconds = 0; SystemTimeToFileTime(&st,&ftLocal); LocalFileTimeToFileTime(&ftLocal,ftm); #else // avoid casts further below LONGLONG *t = (LONGLONG *)ftm; // tartime == number of seconds since midnight Jan 1 1970 (00:00:00) // convert to equivalent 100 nanosecond intervals *t = UInt32x32To64(tartime, 10000000UL); // now base on 1601, add number of 100 nansecond intervals between 1601 & 1970 *t += HUNDREDSECINTERVAL; /* 116444736000000000i64; */ #endif }
bool vtUnzip::change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date) { bool bOK = false; #ifdef _WIN32 #if SUPPORT_WSTRING wstring2 ws; ws.from_utf8(filename); HANDLE hFile = CreateFileW(ws.c_str(), GENERIC_READ | GENERIC_WRITE, 0,NULL, OPEN_EXISTING,0,NULL); #else HANDLE hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0,NULL, OPEN_EXISTING,0,NULL); #endif bOK = (hFile != INVALID_HANDLE_VALUE); if (bOK) { FILETIME ftm,ftLocal,ftLastAcc; BOOL bBOK = GetFileTime(hFile,NULL,&ftLastAcc,NULL); bOK = (bBOK == TRUE); DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); LocalFileTimeToFileTime(&ftLocal,&ftm); SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); CloseHandle(hFile); } #else // TODO: Unix implementation, if needed. Do we care about file dates? bOK = true; #endif return bOK; }
void GetCombinedDateTime ( HWND hwnd, UINT idcDatePicker, UINT idcTimePicker, FILETIME* pFiletime ) { SYSTEMTIME st = {0}, stDate = {0}, stTime = {0}; FILETIME ftLocal; SendDlgItemMessage ( hwnd, idcDatePicker, DTM_GETSYSTEMTIME, 0, (LPARAM) &stDate ); if ( 0 != idcTimePicker ) { SendDlgItemMessage ( hwnd, idcTimePicker, DTM_GETSYSTEMTIME, 0, (LPARAM) &stTime ); } st.wMonth = stDate.wMonth; st.wDay = stDate.wDay; st.wYear = stDate.wYear; st.wHour = stTime.wHour; st.wMinute = stTime.wMinute; st.wSecond = stTime.wSecond; SystemTimeToFileTime ( &st, &ftLocal ); LocalFileTimeToFileTime ( &ftLocal, pFiletime ); }
vtime_t to_utc(vtime_t _time) { __int64 local = (__int64)(_time * 10000000 + epoch_adj); __int64 utc; LocalFileTimeToFileTime((FILETIME*)&local, (FILETIME*)&utc); return vtime_t(utc - epoch_adj) / 10000000; }
// Helper function bool LocalToSystemTime(LPFILETIME lpLocal, LPSYSTEMTIME lpSystem) { false; FILETIME ftSystem; bool bOk = LocalFileTimeToFileTime(lpLocal, &ftSystem) && FileTimeToSystemTime(&ftSystem, lpSystem); return bOk; }
static TINT hal_getdstfromlocaldate(struct THALBase *hal, TDATE *datep) { union { LARGE_INTEGER li; FILETIME ft; } ltime; union { LARGE_INTEGER li; FILETIME ft; } utime; ltime.li.QuadPart = datep->tdt_Int64 * 10; LocalFileTimeToFileTime(<ime.ft, &utime.ft); return (TINT) ((utime.li.QuadPart - ltime.li.QuadPart) / 10000000); }
//设置开始上传的时间 void FtpConnecter::setBeginTime(SYSTEMTIME& beginTimeSt) { FILETIME ft; SystemTimeToFileTime(&beginTimeSt, &ft); LocalFileTimeToFileTime(&ft, &m_BeginTimeFT); m_liBeginTime.LowPart = m_BeginTimeFT.dwLowDateTime; m_liBeginTime.HighPart = m_BeginTimeFT.dwHighDateTime; }
HRESULT CDropHandler::CopyTextToFile(IN TCHAR *pszDestDirectory, IN WCHAR *pszText,OUT TCHAR *pszFullFileNameOut) { SYSTEMTIME st; FILETIME ft; FILETIME lft; HRESULT hr = E_FAIL; TCHAR szTime[512]; GetLocalTime(&st); SystemTimeToFileTime(&st,&ft); LocalFileTimeToFileTime(&ft,&lft); CreateFileTimeString(&lft,szTime,SIZEOF_ARRAY(szTime),FALSE); for(int i = 0;i < lstrlen(szTime);i++) { if(szTime[i] == '/') { szTime[i] = '-'; } else if(szTime[i] == ':') { szTime[i] = '.'; } } TCHAR szFullFileName[MAX_PATH]; TCHAR szFileName[MAX_PATH]; /* TODO: Move text into string table. */ StringCchPrintf(szFileName,SIZEOF_ARRAY(szFileName), _T("Clipboard Text (%s).txt"),szTime); PathCombine(szFullFileName,pszDestDirectory, szFileName); HANDLE hFile = CreateFile(szFullFileName, GENERIC_WRITE,0,NULL,CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD nBytesWritten; WriteFile(hFile,(LPCVOID)pszText, lstrlen(pszText) * sizeof(WCHAR), &nBytesWritten,NULL); CloseHandle(hFile); StringCchCopy(pszFullFileNameOut,MAX_PATH, szFullFileName); hr = S_OK; } return hr; }
FILETIME ArchFile::GetFileTime(size_t fileindex) { FILETIME ft = { (DWORD)-1, (DWORD)-1 }; if (ar && fileindex < filepos.Count() && ar_parse_entry_at(ar, filepos.At(fileindex))) { time64_t filetime = ar_entry_get_filetime(ar); LocalFileTimeToFileTime((FILETIME *)&filetime, &ft); } return ft; }
static int hb_unzipExtractCurrentFileToHandle( unzFile hUnzip, HB_FHANDLE hFile, const char * szPassword ) { unz_file_info ufi; int iResult; if( hFile == FS_ERROR ) return -200; iResult = unzGetCurrentFileInfo( hUnzip, &ufi, NULL, HB_PATH_MAX - 1, NULL, 0, NULL, 0 ); if( iResult != UNZ_OK ) return iResult; iResult = unzOpenCurrentFilePassword( hUnzip, szPassword ); if( iResult != UNZ_OK ) return iResult; if( ! ( ufi.external_fa & 0x40000000 ) ) /* DIRECTORY */ { if( hFile != FS_ERROR ) { char * pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE ); while( ( iResult = unzReadCurrentFile( hUnzip, pString, HB_Z_IOBUF_SIZE ) ) > 0 ) hb_fsWriteLarge( hFile, pString, ( HB_SIZE ) iResult ); hb_xfree( pString ); #if defined( HB_OS_WIN ) { FILETIME ftutc, ft; SYSTEMTIME st; st.wSecond = ( WORD ) ufi.tmu_date.tm_sec; st.wMinute = ( WORD ) ufi.tmu_date.tm_min; st.wHour = ( WORD ) ufi.tmu_date.tm_hour; st.wDay = ( WORD ) ufi.tmu_date.tm_mday; st.wMonth = ( WORD ) ufi.tmu_date.tm_mon + 1; st.wYear = ( WORD ) ufi.tmu_date.tm_year; st.wMilliseconds = 0; if( SystemTimeToFileTime( &st, &ft ) && LocalFileTimeToFileTime( &ft, &ftutc ) ) { SetFileTime( ( HANDLE ) hb_fsGetOsHandle( hFile ), &ftutc, &ftutc, &ftutc ); } } #endif } else iResult = -200 - hb_fsError(); } unzCloseCurrentFile( hUnzip ); return iResult; }
FILETIME DateTime::ToFileTime() const { FILETIME local_file_time = ToLocalFileTime(); FILETIME utc_file_time; BOOL ret = LocalFileTimeToFileTime(&local_file_time, &utc_file_time); ENSURE(RAISE, ret != 0)(LastError()).Require("Failed to convert local file time to file time"); return utc_file_time; }
static int Comp_TimeF(void) //Сравнение времени создания файлов { SYSTEMTIME sysTime; FILETIME fTime, flTime; TimeFileCopy(&sysTime); //Время нового файла SystemTimeToFileTime(&sysTime, &flTime); //Преобразовали время LocalFileTimeToFileTime(&flTime, &fTime); return (CompareFileTime(&DataF.ftLastWriteTime, &fTime) == -1) ? IDOK : IDC_SCIP; //Действие в зависимости от времени записи файла }
BOOL My_LocalFileTimeToFileTime() { CONST FILETIME * lpLocalFileTime=NULL; LPFILETIME lpFileTime=NULL; BOOL returnVal_Real = NULL; BOOL returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; __try{ disableInterception(); returnVal_Real = LocalFileTimeToFileTime (lpLocalFileTime,lpFileTime); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = LocalFileTimeToFileTime (lpLocalFileTime,lpFileTime); error_Intercepted = GetLastError(); }__except(puts("in filter"), 1){puts("exception caught");} return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
static void hugsprim_LocalFileTimeToFileTime_14(HugsStackPtr hugs_root) { HsPtr arg1; HsPtr arg2; HsBool res1; arg1 = hugs->getPtr(); arg2 = hugs->getPtr(); res1 = LocalFileTimeToFileTime(arg1, arg2); hugs->putBool(res1); hugs->returnIO(hugs_root,1); }
FILETIME ZipFile::GetFileTime(size_t fileindex) { FILETIME ft = { -1, -1 }; if (uf && fileindex < fileinfo.Count()) { FILETIME ftLocal; DWORD dosDate = fileinfo.At(fileindex).dosDate; DosDateTimeToFileTime(HIWORD(dosDate), LOWORD(dosDate), &ftLocal); LocalFileTimeToFileTime(&ftLocal, &ft); } return ft; }
/* * The missing "C" runtime mktime() function */ time_t mktime(struct tm *tm) { FILETIME *Local_File_Time; FILETIME File_Time; /* * tm -> Local FILETIME -> FILETIME -> time_t */ Local_File_Time = Convert_tm_To_FILETIME(tm); LocalFileTimeToFileTime(Local_File_Time, &File_Time); return(convert_FILETIME_to_time_t(&File_Time)); }
bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) { #ifdef _WIN32 s[0] = '\0'; SYSTEMTIME st; if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) return false; s = UIntToStringSpec(0, st.wYear, s, 4); s = UIntToStringSpec('-', st.wMonth, s, 2); s = UIntToStringSpec('-', st.wDay, s, 2); if (includeTime) { s = UIntToStringSpec(' ', st.wHour, s, 2); s = UIntToStringSpec(':', st.wMinute, s, 2); if (includeSeconds) UIntToStringSpec(':', st.wSecond, s, 2); } /* sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); if (includeTime) { sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute); if (includeSeconds) sprintf(s + strlen(s), ":%02d", st.wSecond); } */ #else BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds ); FILETIME filetime; LocalFileTimeToFileTime(&ft, &filetime); LARGE_INTEGER ltime; ltime.QuadPart = filetime.dwHighDateTime; ltime.QuadPart = (ltime.QuadPart << 32) | filetime.dwLowDateTime; DWORD dw; RtlTimeToSecondsSince1970(<ime, &dw ); time_t timep = (time_t)dw; struct tm * date = localtime(&timep); sprintf(s, "%04d-%02d-%02d", date->tm_year+1900, date->tm_mon+1,date->tm_mday); if (includeTime) { sprintf(s + strlen(s), " %02d:%02d", date->tm_hour,date->tm_min); if (includeSeconds) sprintf(s + strlen(s), ":%02d", date->tm_sec); } #endif return true; }
void change_file_date(WCHAR *filename,uLong dosdate,tm_unz tmu_date) { FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; HANDLE hFile=CreateFileW(filename,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); LocalFileTimeToFileTime(&ftLocal,&ftm); SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); SysCloseHandle(hFile); return; }
BOOL CorrectTime(SYSTEMTIME& st,Time_t& dt, FILETIME *wdt) { SYSTEMTIME ftm; if(dt == NOT_TIME) memset(wdt, 0, sizeof(*wdt)); else if(dt == 0) SystemTimeToFileTime(&st, dt); if(!LocalFileTimeToFileTime(dt, wdt)) return FALSE; if(dt == NOT_TIME) { ; } else { FILETIME ttm, ltm, t1; SystemTimeToFileTime(&st, &ttm); LocalFileTimeToFileTime(&ttm, <m); while(CompareFileTime(wdt, <m) > 0) { FileTimeToLocalFileTime(wdt, &t1); FileTimeToSystemTime(&t1, &ftm); if(ftm.wDay == 29 && ftm.wMonth == 2) ftm.wYear-=4; else ftm.wYear--; SystemTimeToFileTime(&ftm, &t1); LocalFileTimeToFileTime(&t1, wdt); } } return TRUE; }