コード例 #1
1
static INT_PTR TimestampToStringW(WPARAM wParam,LPARAM lParam)
{
    DBTIMETOSTRINGT *tts = ( DBTIMETOSTRINGT* )lParam;
    LARGE_INTEGER liFiletime;
    FILETIME filetime;
    SYSTEMTIME st;
    TCHAR dateTimeStr[64];
    TCHAR *pDest,*pFormat;
    size_t destCharsLeft, dateTimeStrLen;

    //this huge number is the difference between 1970 and 1601 in seconds
    liFiletime.QuadPart=((__int64)11644473600+(__int64)(DWORD)TimestampToLocal(wParam,0))*10000000;
    filetime.dwHighDateTime = liFiletime.HighPart;
    filetime.dwLowDateTime = liFiletime.LowPart;
    FileTimeToSystemTime(&filetime,&st);
    destCharsLeft = tts->cbDest;
    for ( pFormat = tts->szFormat, pDest=tts->szDest; *pFormat; pFormat++ ) {
        switch(*pFormat) {
        case 't':
            GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 's':
            GetTimeFormat(LOCALE_USER_DEFAULT,0,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 'm':
            GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOMINUTESORSECONDS,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 'd':
            GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        case 'D':
            GetDateFormat(LOCALE_USER_DEFAULT,DATE_LONGDATE,&st,NULL,dateTimeStr,SIZEOF(dateTimeStr));
            break;
        default:
            if ( destCharsLeft ) {
                *pDest++ = *pFormat;
                destCharsLeft--;
            }
            continue;
        }
        dateTimeStrLen = _tcslen(dateTimeStr);
        if (destCharsLeft < dateTimeStrLen) dateTimeStrLen = destCharsLeft;
        CopyMemory(pDest, dateTimeStr, dateTimeStrLen*sizeof(TCHAR));
        destCharsLeft -= dateTimeStrLen;
        pDest += dateTimeStrLen;
    }
    if ( destCharsLeft ) *pDest=0;
    else tts->szDest[ tts->cbDest-1 ] = 0;
    return 0;
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: kxepal/miranda-ng
int SaveSessionDate()
{
	if (session_list[0] != 0) {
		int TimeSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, NULL, NULL, NULL, 0);
		TCHAR *szTimeBuf = (TCHAR*)mir_alloc((TimeSize + 1)*sizeof(TCHAR));

		GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, NULL, NULL, szTimeBuf, TimeSize);

		int DateSize = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, NULL, 0);
		TCHAR *szDateBuf = (TCHAR*)mir_alloc((DateSize + 1)*sizeof(TCHAR));

		GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, szDateBuf, DateSize);
		int lenn = (DateSize + TimeSize + 5);
		TCHAR *szSessionTime = (TCHAR*)mir_alloc(lenn*sizeof(TCHAR));
		mir_sntprintf(szSessionTime, lenn, _T("%s - %s"), szTimeBuf, szDateBuf);

		char szSetting[256];
		mir_snprintf(szSetting, "%s_%d", "SessionDate", 0);
		TCHAR *ptszSaveSessionDate = db_get_tsa(NULL, MODNAME, szSetting);

		db_set_ts(NULL, MODNAME, szSetting, szSessionTime);
		mir_free(szSessionTime);

		if (ptszSaveSessionDate)
			ResaveSettings("SessionDate", 1, g_ses_limit, ptszSaveSessionDate);

		if (szTimeBuf)
			mir_free(szTimeBuf);
		if (szDateBuf)
			mir_free(szDateBuf);
	}
	if (g_bCrashRecovery)
		db_set_b(NULL, MODNAME, "lastSaveCompleted", 1);
	return 0;
}
コード例 #3
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);
	}
}
コード例 #4
0
ファイル: traybin.cpp プロジェクト: alexmarsev/traybin
void ChangeTip(NOTIFYICONDATA* nid, SYSTEMTIME* time) {
	TCHAR *buf, *datef = _T("dddd yyyy.MM.dd");
	HANDLE heap = GetProcessHeap();
	size_t n;

	n = GetDateFormat(LOCALE_USER_DEFAULT, 0, time, datef, NULL, 0);
	buf = (TCHAR*)HeapAlloc(heap, HEAP_ZERO_MEMORY, n * sizeof(TCHAR));
	GetDateFormat(LOCALE_USER_DEFAULT, 0, time, datef, buf, n);
	_stprintf_s(nid->szTip, 64, _T("%s %02d:%02d"), buf, time->wHour, time->wMinute);
	HeapFree(heap, 0, buf);
}
コード例 #5
0
ファイル: parse_miranda.cpp プロジェクト: kmdtukl/miranda-ng
static TCHAR* parseLastSeenDate(ARGUMENTSINFO *ai)
{
	if (ai->argc <= 1)
		return NULL;

	MCONTACT hContact = NULL;
	CONTACTSINFO ci = { 0 };
	ci.cbSize = sizeof(ci);
	ci.tszContact = ai->targv[1];
	ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0);
	int count = getContactFromString(&ci);
	if (count == 1 && ci.hContacts != NULL) {
		hContact = ci.hContacts[0];
		mir_free(ci.hContacts);
	}
	else {
		mir_free(ci.hContacts);
		return NULL;
	}

	TCHAR *szFormat;
	if (ai->argc == 2 || (ai->argc > 2 && mir_tstrlen(ai->targv[2]) == 0))
		szFormat = NULL;
	else
		szFormat = ai->targv[2];

	SYSTEMTIME lsTime = { 0 };
	char *szModule = SEEN_MODULE;
	lsTime.wYear = db_get_w(hContact, szModule, "Year", 0);
	if (lsTime.wYear == 0)
		return NULL;

	lsTime.wMilliseconds = 0;
	lsTime.wSecond = db_get_w(hContact, szModule, "Seconds", 0);
	lsTime.wMinute = db_get_w(hContact, szModule, "Minutes", 0);
	lsTime.wHour = db_get_w(hContact, szModule, "Hours", 0);
	lsTime.wDay = db_get_w(hContact, szModule, "Day", 0);
	lsTime.wDayOfWeek = db_get_w(hContact, szModule, "WeekDay", 0);
	lsTime.wMonth = db_get_w(hContact, szModule, "Month", 0);

	int len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &lsTime, szFormat, NULL, 0);
	TCHAR *res = (TCHAR*)mir_alloc((len + 1)*sizeof(TCHAR));
	if (res == NULL)
		return NULL;

	if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &lsTime, szFormat, res, len) == 0) {
		mir_free(res);
		return NULL;
	}

	return res;
}
コード例 #6
0
ExportGSASnapshot::ExportGSASnapshot(CString filename, CString title, CWnd* pParent /*=NULL*/)
  : CDialog(ExportGSASnapshot::IDD, pParent)
{
  //{{AFX_DATA_INIT(ExportGSASnapshot)
  m_desc = _T("");
  m_notes = _T("");
  m_title = _T("");
  //}}AFX_DATA_INIT
  m_title = title;
  m_filename = filename;
  char date[100];
  char time[100];
  
  GetDateFormat(LOCALE_USER_DEFAULT,
                DATE_SHORTDATE,
                NULL,
                NULL,
                date,
                100);
  GetTimeFormat(LOCALE_USER_DEFAULT,
                0,
                NULL,
                NULL,
                time,
                100);
  m_desc.Format("%s %s", date, time);
}
コード例 #7
0
wstring formatDate(StringBuffer& date) {
    
    wstring dd(TEXT(""));
    wchar_t* wdate = toWideChar(date);
    if (wdate == NULL) {
        return dd;
    }
    wchar_t data[80];
    wchar_t formatDate[80];
    int found = 0;
    SYSTEMTIME timeDest;
    swscanf_s(wdate, L"%4d%2d%2d", &timeDest.wYear, &timeDest.wMonth, &timeDest.wDay);
    
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, data, 80);

    dd = data;            
    if ((found = dd.find(TEXT("dddd, "))) != wstring::npos) {
        dd.replace(found, 6, TEXT(""));
    } else if ((found = dd.find(TEXT("dddd,"))) != wstring::npos) {
        dd.replace(found, 5, TEXT(""));
    }else if ((found = dd.find(TEXT("dddd"))) != wstring::npos) {
        dd.replace(found, 4, TEXT(""));
    }

    trim(dd);            
    GetDateFormat(LOCALE_USER_DEFAULT, NULL, &timeDest, dd.c_str(), formatDate, 80); 
    dd = formatDate;
    return dd;
}
コード例 #8
0
ファイル: files.cpp プロジェクト: Smeetal/BrainBay
void edfheader_to_physical(EDFHEADERStruct * from, EDFHEADER_PHYSICALStruct * to)
{
	int len,t;
	char * ch;
	SYSTEMTIME st;
	char actdate[10];
	char acttime[10];

	len=256+256*from->channels;

	ch=(char *)to;
	for(t=0;t<256;t++,ch++) *ch=' ';

	GetSystemTime(&st);              // gets current time
	GetDateFormat(0, 0, &st, "dd.MM.yy" , actdate, 9);actdate[8]=0;
	GetTimeFormat(0, 0, &st, "HH.mm.ss" , acttime, 9);acttime[8]=0;

	strcpy(to->startdate,actdate); 
	strcpy(to->starttime,acttime); 


	strcpy(to->version,"0"); 
	strcpy(to->patient,from->patient); 
	strcpy(to->recording,from->device);
    sprintf(to->records,"%d",from->segments);
	sprintf(to->duration,"%d",1);
	sprintf(to->channels,"%d",from->channels);
	sprintf(to->headerlength,"%d",len);

	ch=(char *)to;
	for(t=0;t<256;t++,ch++) if (*ch==0) *ch=' ';
	to->end=0;
}
コード例 #9
0
	BOOL CallContextDayNote(SYSTEMTIME Time, HWND hCalendar)
	{
		CStringArray arr;
		arr.Add(_l("New reminder"));
		arr.Add(_l("Add date to clipboard"));
		int iSelection=SelectFromMenu(arr,0);
		if(iSelection<0){
			return 0;
		}
		if(iSelection==0){
			return -1;
		}
		CString s="";
		COleDateTime tm;//=COleDateTime(Time);
		tm.SetDate(Time.wYear,Time.wMonth,Time.wDay);
		if(strlen(szDateFormat)==0){
			s=DateFormat(tm,FALSE);
		}else{
			SYSTEMTIME EventTime;
			tm.GetAsSystemTime(EventTime);
			char szTmp[1020]={0};
			GetDateFormat(LOCALE_USER_DEFAULT,0,&EventTime,szDateFormat,szTmp,sizeof(szTmp));
			s=szTmp;
		}
		BOOL bThroughGlobal=0;
		USES_CONVERSION;
		SetClipboardText(A2W(s),bThroughGlobal,0);
		return 0;
	};
コード例 #10
0
ファイル: DisplayCache.cpp プロジェクト: pierrecoll/urlcache
//////////////////////////////////////////////////////////////////////
// Methode : GetTime
// Resume : Return Time cache entry
// In : FILETIME ft : the cache entry
// Out : CString Time of the cache entry 
//////////////////////////////////////////////////////////////////////
CString GetTime(FILETIME ft)
{
	SYSTEMTIME st;

	char szLocalDate[255];
	char szLocalTime[255];   

	CString strtemp;

	FileTimeToLocalFileTime( &ft, &ft );
	FileTimeToSystemTime( &ft, &st );

	GetDateFormat(	LOCALE_USER_DEFAULT, 
					DATE_SHORTDATE, 
					&st, 
					NULL,
					szLocalDate, 
					255 );

	GetTimeFormat(	LOCALE_USER_DEFAULT, 
					0, 
					&st, 
					NULL, 
					szLocalTime, 
					255 );
	
	strtemp = szLocalDate;
	strtemp += " | ";
	strtemp += szLocalTime ;
	return (strtemp);
}
コード例 #11
0
ファイル: os_time.c プロジェクト: osrf/opensplice
/** \brief Translate calendar time into readable string representation
 *
 * Possible Results:
 * - returns buf if buf != NULL
 * - returns NULL if buf == NULL
 */
os_size_t
os_ctimeW_r(
    os_timeW *t,
    char *buf,
    os_size_t bufsz)
{
    os_size_t result = 0;
    SYSTEMTIME systemTime;
    FILETIME systemTimeSince1601;
    DWORD64 dw64Time;
    DWORD64 dw64MAXDWORD = MAXDWORD;
    wchar_t format[32];
    char *fstr;

    /* Using win32 ctime here */
    if (buf)
    {
        int iSizeOfBuffer;

        dw64Time = (t->wt)/100;

        systemTimeSince1601.dwHighDateTime = (dw64Time / (dw64MAXDWORD+1));
        systemTimeSince1601.dwLowDateTime = (dw64Time % (dw64MAXDWORD+1));
        FileTimeToSystemTime(&systemTimeSince1601, &systemTime);

        /* Time is in UTC here */
        GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &systemTime, L"yyyy'-'MM'-'dd'T'HH':'mm':'ss", format, 32);
        /* convert wide str to multi byte str */
        fstr = wce_wctomb(format);
        result = snprintf(buf, bufsz, "%s", fstr);
        os_free(fstr);
    }
    return result;

}
コード例 #12
0
ファイル: A2Date.cpp プロジェクト: shysaur/ChiptuneMDImporter
//**************************************************************************************************
b8 A2Date::ToStr(s8 *str)
{
	if (!*(s32*)&date) return 0;

#ifdef	_WIN32
	SYSTEMTIME	time;

	time.wYear = date.y;
	time.wMonth = date.m;
	time.wDayOfWeek = 0;
	time.wDay = date.d;
	time.wHour = 0;
	time.wMinute = 0;
	time.wSecond = 0;
	time.wMilliseconds = 0;

	GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, str, -1);
#else
//	sprintf(str, "%i.%i.%i", date.y, date.m, date.d);
//	sprintf(str, "%i.%i.%i", date.d, date.m, date.y % 100);
	sprintf(str, "%i/%i/%i", date.m, date.d, date.y % 100);
#endif

	return 1;
}
コード例 #13
0
ファイル: Data.c プロジェクト: tobynet/clcl
/*
 * data_get_modified_string - 更新日時文字列を取得
 */
BOOL data_get_modified_string(const DATA_INFO *di, TCHAR *ret)
{
    SYSTEMTIME sys_time;
    TCHAR str_day[BUF_SIZE], str_time[BUF_SIZE];
    TCHAR *p;

    if (di->type != TYPE_ITEM ||
            (di->modified.dwLowDateTime == 0 && di->modified.dwHighDateTime == 0)) {
        *ret = TEXT('\0');
        return FALSE;
    }
    // ファイルタイムをシステムタイムに変換
    if (FileTimeToSystemTime(&di->modified, &sys_time) == FALSE) {
        *ret = TEXT('\0');
        return FALSE;
    }
    // 日付文字列の取得
    p = option.data_date_format;
    if (p == NULL || *p == TEXT('\0')) {
        p = NULL;
    }
    GetDateFormat(0, 0, &sys_time, p, str_day, BUF_SIZE - 1);
    // 時間文字列の取得
    p = option.data_time_format;
    if (p == NULL || *p == TEXT('\0')) {
        p = NULL;
    }
    GetTimeFormat(0, 0, &sys_time, p, str_time, BUF_SIZE - 1);

    wsprintf(ret, TEXT("%s %s"), str_day, str_time);
    return TRUE;
}
コード例 #14
0
CString FiletimeAsString(FILETIME filetime)
{
	SYSTEMTIME sysTime;
	if(0 == FileTimeToSystemTime(&filetime,&sysTime))
		return _T("");

	SYSTEMTIME localTime;

	TIME_ZONE_INFORMATION tzi;
	GetTimeZoneInformation(&tzi);
	
	if (!SystemTimeToTzSpecificLocalTime(&tzi, &sysTime, &localTime))
		return _T("");

	CString sDate;
	TCHAR szDateBuffer[20] = {0};
	TCHAR szTimeBuffer[20] = {0};

	if (0 == GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &localTime, NULL, szDateBuffer, 20) ||
	    0 == GetTimeFormat(LOCALE_USER_DEFAULT, 0, &localTime, NULL, szTimeBuffer, 20))
		return _T("");

	sDate.Format(_T("%s %s"), szDateBuffer, szTimeBuffer);

   if(-1 != sDate.Find(_T("1601")))
      return _T("");

	return sDate;
}
コード例 #15
0
ファイル: DateTime.cpp プロジェクト: VlaBst6/FileTest
// Converts locale-specific month name to month number
// Only converts genitives
static WORD MonthNameGenitiveToNumber(LPCTSTR szStr, int * piMonthNameLength)
{
    SYSTEMTIME stTemp = {0};
    TCHAR szMonthName[80];
    int nLength;

    // Prepare the temporary SYSTEMTIME structure
    // Note: The recommended way to get month name as genitive is to use GetDateFormat
    // with "ddMMMM" and compare month name starting at second position
    stTemp.wDay = 1;
    stTemp.wYear = 2000;

    // Go through all month names.
    for(stTemp.wMonth = 1; stTemp.wMonth <= 13; stTemp.wMonth++)
    {
        // Get genitive of month name
        nLength = GetDateFormat(LOCALE_USER_DEFAULT, 0, &stTemp, _T("ddMMMM"), szMonthName, _maxchars(szMonthName));
        if(nLength < 3)
            break;

        // Compare the month name
        if(!_tcsnicmp(szStr, &szMonthName[2], nLength - 3))
        {
            *piMonthNameLength = (nLength - 3);
            return stTemp.wMonth;
        }
    }

    // Month name genitive not recognized
    return 0xFFFF;
}
コード例 #16
0
ファイル: utility.cpp プロジェクト: Kaldaien/BMT
// Gets the timestamp on the current backup file
std::wstring
BMT_GetBackupFileTime (void)
{
  WIN32_FIND_DATA FindFileData;

  HANDLE hFileBackup = FindFirstFile (std::wstring (bmt::XML::install_path + L"..\\..\\BMGame\\Config\\BmSystemSettings.bmt").c_str (), &FindFileData);

  FindClose (hFileBackup);

  FILETIME   ftModified;
  FileTimeToLocalFileTime (&FindFileData.ftLastWriteTime, &ftModified);

  SYSTEMTIME stModified;
  FileTimeToSystemTime (&ftModified, &stModified);

  wchar_t wszFileTime [512];

  GetDateFormat (LOCALE_CUSTOM_UI_DEFAULT, DATE_AUTOLAYOUT, &stModified, NULL, wszFileTime, 512);

  std::wstring date_time = wszFileTime;

  GetTimeFormat (LOCALE_CUSTOM_UI_DEFAULT, TIME_NOSECONDS, &stModified, NULL, wszFileTime, 512);

  date_time += L" ";
  date_time += wszFileTime;

  return date_time;
}
コード例 #17
0
ファイル: utility.cpp プロジェクト: Kaldaien/BMT
// Gets the timestamp on the current config file
std::wstring
BMT_GetConfigFileTime (void)
{
  //
  // XXX: It's possible that one file is newer than another, but for now let's
  //        assume SystemSettings.ini is always the newest and then see how
  //          much trouble that assumption gets us into down the line ;)
  //
  WIN32_FIND_DATA FindFileData;

  HANDLE hFileBackup = FindFirstFile (std::wstring (bmt::XML::install_path + L"..\\..\\BMGame\\Config\\BmSystemSettings.ini").c_str (), &FindFileData);

  FILETIME   ftModified;
  FileTimeToLocalFileTime (&FindFileData.ftLastWriteTime, &ftModified);

  SYSTEMTIME stModified;
  FileTimeToSystemTime (&ftModified, &stModified);

  FindClose (hFileBackup);

  wchar_t wszFileTime [512];

  GetDateFormat (LOCALE_CUSTOM_UI_DEFAULT, DATE_AUTOLAYOUT, &stModified, NULL, wszFileTime, 512);

  std::wstring date_time = wszFileTime;

  GetTimeFormat (LOCALE_CUSTOM_UI_DEFAULT, TIME_NOSECONDS, &stModified, NULL, wszFileTime, 512);

  date_time += L" ";
  date_time += wszFileTime;

  return date_time;
}
コード例 #18
0
ファイル: win_handy.cpp プロジェクト: prestocore/browser
uni_char* StrGetDateTime ( CONST SYSTEMTIME *pSystemTime, uni_char* szResult, int maxlen, BOOL fSec)
{
	if( szResult && maxlen>=1)
	{
		*szResult = 0;
		if( pSystemTime)
		{
			int lenDate = GetDateFormat( LOCALE_USER_DEFAULT, DATE_SHORTDATE, pSystemTime, NULL, szResult, maxlen)-1;
			if( lenDate>0)
			{
				int lenRemaining = maxlen - lenDate;
				if( lenRemaining > 2)
				{
					szResult[lenDate] = ' ';
					szResult[lenDate+1] = 0;
					-- lenRemaining;
					++ lenDate;
#ifdef _DEBUG
					int lenTime =
#endif
					GetTimeFormat( LOCALE_USER_DEFAULT, (fSec ? 0 : TIME_NOSECONDS), pSystemTime, NULL, szResult+lenDate, lenRemaining);
					OP_ASSERT(lenTime>0);
				}
			}
		}	
	}
	return szResult;
}
コード例 #19
0
ファイル: IdlePageMain.c プロジェクト: kiapper/Watch
static void DisplayDate(void)
{
  if ( QueryFirstContact() )
  {
    int First;
    int Second;

    /* determine if month or day is displayed first */
    if ( GetDateFormat() == MONTH_FIRST )
    {
      First = GetRTCMON();
      Second = GetRTCDAY();
    }
    else
    {
      First = GetRTCDAY();
      Second = GetRTCMON();
    }
    if ( GetTimeFormat() == TWELVE_HOUR )
    {
    	DisplayDayMonth(First, Second, 20);
    }
    else
    {
    	int year = GetRTCYEAR();
    	DisplayDayMonth(First, Second, 10);

    	/* Write the year */
    	DisplayYear(year, 20, 8);
    }
  }
}
コード例 #20
0
ファイル: Server.cpp プロジェクト: Avoidnf8/xbmc-fork
void CServer::ShowStatus(_int64 eventDate, LPCTSTR msg, int nType)
{
	USES_CONVERSION;
	TIME_ZONE_INFORMATION tzInfo;
	BOOL res=GetTimeZoneInformation(&tzInfo);
	_int64 offset = tzInfo.Bias+((res==TIME_ZONE_ID_DAYLIGHT)?tzInfo.DaylightBias:tzInfo.StandardBias);
	offset*=60*10000000;
	eventDate-=offset;
	LPCSTR str=T2CA(msg);
	char *pBuffer=new char[strlen(str) + 1 + 8];
	*pBuffer=nType;
	memcpy(pBuffer + 1, &eventDate, 8);
	memcpy(pBuffer + 1 + 8, str, strlen(str));
	if (m_pAdminInterface)
		m_pAdminInterface->SendCommand(2, 4, pBuffer, strlen(str) + 1 + 8);
	delete [] pBuffer;

	//Log string
	if (m_pFileLogger)
	{
		FILETIME fFileTime;
		SYSTEMTIME sFileTime;
		fFileTime.dwHighDateTime = (DWORD)(eventDate>>32);
		fFileTime.dwLowDateTime = (DWORD)(eventDate %0xFFFFFFFF);
		FileTimeToSystemTime(&fFileTime, &sFileTime);
		char text[80];
		if (!GetDateFormat(
			LOCALE_USER_DEFAULT,               // locale for which date is to be formatted
			DATE_SHORTDATE,             // flags specifying function options
			&sFileTime,  // date to be formatted
			0,          // date format string
			text,          // buffer for storing formatted string
			80                // size of buffer
			))
			return;
		
		CStdString text2=" ";
		text2+=text;
		
		if (!GetTimeFormat(
			LOCALE_USER_DEFAULT,               // locale for which date is to be formatted
			TIME_FORCE24HOURFORMAT,             // flags specifying function options
			&sFileTime,  // date to be formatted
			0,          // date format string
			text,          // buffer for storing formatted string
			80                // size of buffer
			))
			return;

		text2+=" ";
		text2+=text;
		CStdString str = msg;
		int pos=str.Find("-");
		if (pos!=-1)
		{
			str.Insert(pos, text2 + " ");
		}
		m_pFileLogger->Log(str);
	}
}
コード例 #21
0
char const* dateHeader() {
  static char buf[200];
#if !defined(_WIN32_WCE)
  time_t tt = time(NULL);
  strftime(buf, sizeof buf, "Date: %a, %b %d %Y %H:%M:%S GMT\r\n", gmtime(&tt));
#else
  // WinCE apparently doesn't have "time()", "strftime()", or "gmtime()",
  // so generate the "Date:" header a different, WinCE-specific way.
  // (Thanks to Pierre l'Hussiez for this code)
  // RSF: But where is the "Date: " string?  This code doesn't look quite right...
  SYSTEMTIME SystemTime;
  GetSystemTime(&SystemTime);
  WCHAR dateFormat[] = L"ddd, MMM dd yyyy";
  WCHAR timeFormat[] = L"HH:mm:ss GMT\r\n";
  WCHAR inBuf[200];
  DWORD locale = LOCALE_NEUTRAL;

  int ret = GetDateFormat(locale, 0, &SystemTime,
                          (LPTSTR)dateFormat, (LPTSTR)inBuf, sizeof inBuf);
  inBuf[ret - 1] = ' ';
  ret = GetTimeFormat(locale, 0, &SystemTime,
                      (LPTSTR)timeFormat,
                      (LPTSTR)inBuf + ret, (sizeof inBuf) - ret);
  wcstombs(buf, inBuf, wcslen(inBuf));
#endif
  return buf;
}
コード例 #22
0
void FarLog::Log( int Level, char const * Fmt, va_list argPtr )
{
	if ( m_File == NULL || Level > m_Level || Fmt == NULL || *Fmt == '\0' )
		return;
	
	if ( m_Tmp == NULL )
		m_Tmp = new char[ 1024 ]; // see wvsprintf help
	
	SYSTEMTIME LocalTime; GetLocalTime( &LocalTime );

	int nLen;
	
	nLen = GetDateFormat( LOCALE_USER_DEFAULT, 0, &LocalTime, NULL, m_Tmp, 0x1000 ) - 1;
	m_File->Write( m_Tmp, nLen );

	m_File->Write( "\x20", 1 );

	nLen = GetTimeFormat( LOCALE_USER_DEFAULT, 0, &LocalTime, NULL, m_Tmp, 0x1000 ) - 1;
	m_File->Write( m_Tmp, nLen );
	
	if ( Level == 1 )
		m_File->Write( " Error: ", 8 );
	else if ( Level == 2 )
		m_File->Write( " Warning: ", 10 );
	else 
		m_File->Write( "\x20", 1 );

	nLen = wvsprintf( m_Tmp, Fmt, argPtr );

	m_File->Write( m_Tmp, nLen );

	if ( m_Tmp[ nLen - 1 ] != '\n' )
		m_File->Write( "\r\n", 2 );
}
コード例 #23
0
ファイル: classMTime.cpp プロジェクト: Seldom/miranda-ng
WORD	MTime::DateFormatAlt(LPTSTR ptszTimeFormat, WORD cchTimeFormat)
{
	if (!ptszTimeFormat || !cchTimeFormat)
		return 0;

	WORD wRes = DateFormat(ptszTimeFormat, cchTimeFormat);
	if (wRes != 0)
		return wRes;

	SYSTEMTIME AltSysTime = _SysTime;
	MTime mtNow;
	mtNow.GetLocalTime();
	AltSysTime.wYear=mtNow.Year();

	if ((cchTimeFormat = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &AltSysTime, NULL, ptszTimeFormat, cchTimeFormat)) == 0) {
		*ptszTimeFormat = 0;
		return 0;
	}
	
	TCHAR tszText[10];
	_itot(mtNow.Year(), tszText, 10);
	TCHAR * tszYear = _tcsstr(ptszTimeFormat, tszText);

	if (tszYear && mir_tstrlen(tszYear) == 4)
		mir_tstrcpy(tszYear, _T("????"));
	else {
		*ptszTimeFormat = 0;
		return 0;
	}
	
	return cchTimeFormat;
}
コード例 #24
0
ファイル: wumf.cpp プロジェクト: 0xmono/miranda-ng
void LogWumf(PWumf w)
{
	TCHAR str[256];
	LPTSTR lpstr;
	TCHAR lpDateStr[20];
	TCHAR lpTimeStr[20];
	SYSTEMTIME time;
	DWORD bytes;
	
	if (!WumfOptions.LogFolders && (w->dwAttr & FILE_ATTRIBUTE_DIRECTORY)) return;

	if (hLog == INVALID_HANDLE_VALUE || hLog == NULL)
	{
		hLog = CreateFile(WumfOptions.LogFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hLog == INVALID_HANDLE_VALUE)
		{
			FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
			    NULL,
			    GetLastError(),
			    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
			    (LPTSTR) &lpstr, 0, NULL);
			mir_sntprintf(str, SIZEOF(str), _T("Can't open log file %s\nError:%s"), WumfOptions.LogFile, lpstr);
			LocalFree(lpstr);		
			MessageBox( NULL, str, TranslateT("Error opening file"), MB_OK | MB_ICONSTOP);
			WumfOptions.LogToFile = FALSE;
		}
	}
	GetLocalTime(&time);
	GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, lpDateStr, 20);
	GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &time, NULL, lpTimeStr, 20);
	mir_sntprintf(str, SIZEOF(str), _T("%s %s %20s\t%s\r\n\0"), lpDateStr, lpTimeStr, w->szUser, w->szPath);
	SetFilePointer(hLog, 0, NULL, FILE_END);
	WriteFile(hLog, str, (DWORD)_tcslen(str), &bytes, NULL);
}
コード例 #25
0
ファイル: files.cpp プロジェクト: Smeetal/BrainBay
void write_logfile(char * format, ...)
{
	char actdate[10];
	char acttime[10];
	char tmpstr [512];
	SYSTEMTIME st;
	DWORD dwritten;
    va_list argp; 

	strcpy(tmpstr,GLOBAL.resourcepath); 
	strcat(tmpstr,"bbay.log");
	
    logfile=CreateFile(tmpstr, GENERIC_WRITE|GENERIC_READ , 0, NULL, OPEN_EXISTING, 0,NULL);
    SetFilePointer(logfile,0,NULL,FILE_END);

	GetSystemTime(&st);              // gets current time
	GetDateFormat(0, 0, &st, "dd.MM.yy" , actdate, 9);actdate[8]=0;
	GetTimeFormat(0, 0, &st, "HH:mm:ss" , acttime, 9);acttime[8]=0;
	wsprintf(tmpstr,"%s - %s ",actdate,acttime);
	WriteFile(logfile,tmpstr,strlen(tmpstr),&dwritten,NULL);

    va_start(argp, format); 
    vsnprintf(tmpstr,sizeof(tmpstr),format,argp); 
	WriteFile(logfile,tmpstr,strlen(tmpstr),&dwritten,NULL);
    va_end(argp); 

	WriteFile(logfile,"\r\n",2,&dwritten,NULL);
	CloseHandle(logfile);
}
コード例 #26
0
ファイル: nGame.cpp プロジェクト: m1h4/MissleCommand
bool nGame::AddHiScore(unsigned long value)
{
	if(!value)
		return false;

	static const unsigned long maxScores = 20;

	for(unsigned long i = 0; i < m_HiScores.size(); i++)
		if(m_HiScores[i].score < value)
			break;

	HiScore hiscore;

	static char time[100];
	GetTimeFormat(LOCALE_USER_DEFAULT,NULL,NULL,NULL,time,100);

	static char date[100];
	GetDateFormat(LOCALE_USER_DEFAULT,DATE_LONGDATE,NULL,NULL,date,100);

	hiscore.score = value;
	hiscore.time = nString(time) + " " + nString(date);

	if(i < m_HiScores.size())
		m_HiScores.insert(m_HiScores.begin() + i,hiscore);
	else
		m_HiScores.push_back(hiscore);

	while(m_HiScores.size() > maxScores)
		m_HiScores.pop_back();

	return true;
}
コード例 #27
0
		void LogDateAndTime()
		{
			std::string message = "Application started at ";

			// Time
			const int bufferLength = 512;
			char buffer[bufferLength];
			{
				LCID useUsersLocale = LOCALE_USER_DEFAULT;
				DWORD useDefaultFormatOptions = 0;
				const SYSTEMTIME* useCurrentLocalTime = NULL;
				const char* useDefaultFormatPicture = NULL;
				int charactersWrittenToBufferCount = GetTimeFormat(
					useUsersLocale, useDefaultFormatOptions, useCurrentLocalTime, useDefaultFormatPicture, buffer, bufferLength );
				message += charactersWrittenToBufferCount > 0 ? buffer : "unknown time";
			}

			message += " on ";

			// Date
			{
				LCID useUsersLocale = LOCALE_USER_DEFAULT;
				DWORD useDefaultFormatOptions = 0;
				const SYSTEMTIME* useCurrentLocalDate = NULL;
				const char* useDefaultFormatPicture = NULL;
				int charactersWrittenToBufferCount = GetDateFormat(
					useUsersLocale, useDefaultFormatOptions, useCurrentLocalDate, useDefaultFormatPicture, buffer, bufferLength );
				message += charactersWrittenToBufferCount > 0 ? buffer : "unknown date";
			}

			cs6963::LogMessage( message );
		}
コード例 #28
0
ファイル: nclog.cpp プロジェクト: hjgode/logging_ce
TCHAR* logDateTime(){
	static TCHAR str[64];
	TCHAR lpTimeStr[32];
	TCHAR lpDateStr[32];
	LONG res;
	wsprintf(str,L"");
	//Read the system time
	res = GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
							TIME_FORCE24HOURFORMAT,
							NULL,
							L"hh:mm:ss",
							lpTimeStr,
							sizeof (lpTimeStr ) * sizeof(TCHAR));
	if (res == 0)
	{
		wcscpy(lpTimeStr, L"err");
	}

	//Read the system date
	res = GetDateFormat(  LOCALE_SYSTEM_DEFAULT,
						  NULL,
						  NULL,
						  L"dd.MM.yyyy",
						  lpDateStr,
						  sizeof (lpDateStr) * sizeof(TCHAR));
	if (res == 0)
	{
		wcscpy(lpDateStr, L"err");
	}

	wsprintf(str, L"%s %s", lpDateStr, lpTimeStr);
	return str;
}
コード例 #29
0
ファイル: Server.cpp プロジェクト: soulic/FileZilla-Server
void CServer::ShowStatus(DWORD eventDateHigh, DWORD eventDateLow, LPCTSTR msg, int nType)
{
	auto utf8 = ConvToNetwork(msg);
	if (utf8.empty())
		return;

	char *pBuffer = new char[utf8.size() + 1 + 8];
	*pBuffer = nType;
	memcpy(pBuffer + 1, &eventDateHigh, 4);
	memcpy(pBuffer + 5, &eventDateLow, 4);
	memcpy(pBuffer + 1 + 8, utf8.c_str(), utf8.size());
	if (m_pAdminInterface)
		m_pAdminInterface->SendCommand(2, 4, pBuffer, utf8.size() + 1 + 8);
	delete [] pBuffer;

	//Log string
	if (m_pFileLogger) {
		FILETIME fFileTime;
		SYSTEMTIME sFileTime;
		fFileTime.dwHighDateTime = eventDateHigh;
		fFileTime.dwLowDateTime = eventDateLow;
		if (!FileTimeToSystemTime(&fFileTime, &sFileTime)) {
			return;
		}
		TCHAR text[80];
		if (!GetDateFormat(
			LOCALE_USER_DEFAULT,			// locale for which date is to be formatted
			DATE_SHORTDATE,					// flags specifying function options
			&sFileTime,						// date to be formatted
			0,								// date format string
			text,							// buffer for storing formatted string
			80								// size of buffer
			))
			return;

		CStdString text2 = _T(" ");
		text2 += text;

		if (!GetTimeFormat(
			LOCALE_USER_DEFAULT,			// locale for which date is to be formatted
			TIME_FORCE24HOURFORMAT,			// flags specifying function options
			&sFileTime,						// date to be formatted
			0,								// date format string
			text,							// buffer for storing formatted string
			80								// size of buffer
			))
			return;

		text2 += _T(" ");
		text2 += text;
		CStdString str = msg;
		int pos = str.Find(_T("-"));
		if (pos!=-1)
		{
			str.Insert(pos, text2 + _T(" "));
		}
		m_pFileLogger->Log(str);
	}
}
コード例 #30
-1
ファイル: Log.cpp プロジェクト: tianyx/TxUIProject
void Log::ReallyPrint(LPCTSTR format, va_list ap) 
{

	SYSTEMTIME current;
	GetLocalTime(&current);
	if (memcmp(&m_lastLogT, &current, sizeof(SYSTEMTIME)) != 0)
	{
		m_lastLogT = current;
		TCHAR time_str[50] = {0};
		TCHAR date_str[50] = {0};

		int nRet = GetDateFormat(LOCALE_USER_DEFAULT, NULL, &current, TEXT("dd"),  date_str, sizeof(date_str));
		nRet = GetTimeFormat(LOCALE_USER_DEFAULT,NULL, &current,TEXT("hh:mm:ss"),time_str,sizeof(time_str));
		
		TCHAR time_buf[50];
		wsprintf(time_buf, TEXT("<%s %s>:"),date_str, time_str);		
		ReallyPrintLine(time_buf);
	}


	// Prepare the complete log message
	TCHAR line[LINE_BUFFER_SIZE];
	memset(line, 0, sizeof(line));
	int len = 0;
#ifdef _UNICODE
	_vsnwprintf(line, sizeof(line) - 2 * sizeof(TCHAR), format, ap);
	len = wcslen(line);

#else
	_vsnprintf(line, sizeof(line) - 2 * sizeof(TCHAR), format, ap);
	len = strlen(line);

#endif // _UNICODE
	line[LINE_BUFFER_SIZE-2] = (TCHAR)'\0';
#if (!defined(_UNICODE) && !defined(_MBCS))
	if (len > 0 && len <= sizeof(line) - 2 * sizeof(TCHAR) && line[len-1] == (TCHAR)'\n') {
		// Replace trailing '\n' with MS-DOS style end-of-line.
		line[len-1] = (TCHAR)'\r';
		line[len] =   (TCHAR)'\n';
		line[len+1] = (TCHAR)'\0';
	}
#endif
	
	ReallyPrintLine(line);
	ReallyPrintLine(TEXT("\r\n"));

	//if overfollow create new log
	if (m_tofile)
	{
		nTotalLogWrited += len;
		//max log size = 10m
		if (nTotalLogWrited > 1024*1024*10)
		{
			CloseFile();
			CString strNewFile = m_strOrgFileName;
			SetFile(strNewFile, false);
		}

	}
}