按照控制面板区域设置显示时间的格式函数

来源:互联网 发布:怎么在mac上卸载程序 编辑:程序博客网 时间:2024/05/16 11:30

void CTimerWinView::OnDraw(CDC* pDC)
{
 CTimerWinDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: add draw code for native data here

 struct tm *newtime;
 char am_pm[] = "AM";
 time_t long_time;
 
 time( &long_time );                /* Get time as long integer. */
 newtime = localtime( &long_time ); /* Convert to local time. */
 
 if( newtime->tm_hour > 12 )        /* Set up extension. */
  strcpy( am_pm, "PM" );
 if( newtime->tm_hour > 12 )        /* Convert 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;

 pDC->TextOut(10,10, asctime(newtime));

 TCHAR Buf[2];
 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDATE , Buf, 2);
 pDC->TextOut(10,50, Buf);

 HANDLE File = CreateFile("c://abc.txt", GENERIC_READ, FILE_SHARE_READ,
  NULL,     // default security
  OPEN_EXISTING,   // existing file only
  FILE_ATTRIBUTE_NORMAL, // normal file
  NULL);
 FILETIME ft;
 GetFileTime(File, &ft, NULL , NULL);
 SYSTEMTIME st;
 FileTimeToSystemTime(&ft, &st);

 TCHAR Buffer[100];
 GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, Buffer, 100);
 pDC->TextOut(10, 80, Buffer);
}

/* Output

    Wed Jun 20 02:03:28 2007

   2

  2007-6-20

*/