91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 8KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2021-05-16
  • 語言: C/C++
  • 標簽: NetTime??Server??C++Time??

資源簡介

2019月4月30日 MFC 控制臺 獲取網絡時間,兩個服務器,兩種方法,編譯可用,親測有效

資源截圖

代碼片段和文件信息

//?GetNetTime.cpp?:?定義控制臺應用程序的入口點。
//

#include?“stdafx.h“
#include?“GetNetTime.h“

#include?
#include?
#include?
#pragma?comment(lib?“Wininet.lib“)?

#ifdef?_DEBUG
#define?new?DEBUG_NEW
#endif


//?唯一的應用程序對象

CWinApp?theApp;

using?namespace?std;

int?IsLeap(unsigned?short?year)
{
return?((year?%?4?==?0)?&&?(year?%?100?!=?0)?||?(year?%?400?==?0));
}

CString?MillSecond2LocalTime(long?long?time?long?timezone)
{
const?int?monthLengths[2][13]?=?{
{?0?31?59?90?120?151?181?212?243?273?304?334?365?}
{?0?31?60?91?121?152?182?213?244?274?305?335?366?}
};
const?int?yearLengths[2]?=?{?365?366?};
int?year(0)?month(0)?minMonth(0)?maxMonth(0)?days(0)?clock(0)?isLeap(0)?day(0)?hour(0)?minute(0)?second(0);
time?/=?1000;
time?+=?timezone?*?60?*?60;
days?=?time?/?86400;//天數
clock?=?time?%?86400;//小時數

if?(clock? {
clock?+=?86400;
days?-=?1;
}

if?(days?>=?0)
{
year?=?days?/?366;
days?-=?year?*?365?+?(year?+?1)?/?4?-?(year?+?69)?/?100?+?(year?+?369)?/?400;

for?(year?=?year?+?1970;;?year++)
{
isLeap?=?IsLeap(year);
if?(days? {
break;
}
days?-=?yearLengths[isLeap];
}
}
else
{
year?=?days?/?366;
days?-=?year?*?365?+?(year?-?2)?/?4?-?(year?-?30)?/?100?+?(year?-?30)?/?400;
for?(year?=?year?+?1970?-?1;;?year--)
{
isLeap?=?false;
days?+=?yearLengths[isLeap];
if?(days?>=?0)
{
break;
}
}
}

minMonth?=?0;
maxMonth?=?12;
for?(month?=?5;?month<12?&&?month>0;?month?=?(minMonth?+?maxMonth)?/?2)
{
if?(days? {
maxMonth?=?month;
}
else?if?(days?>=?monthLengths[isLeap][month?+?1])
{
minMonth?=?month;
}
else
{
break;
}
}
days?-=?monthLengths[isLeap][month];
month++;
day?=?days?+?1;

hour?=?clock?/?3600;
clock?=?clock?%?3600;
minute?=?clock?/?60;
second?=?clock?%?60;

//printf(“%d-%02d-%02d?%02d:%02d:%02d“?year?month?day?hour?minute?second);
CString?tm;
tm.Format(“%d-%02d-%02d?%02d:%02d:%02d“?year?month?day?hour?minute?second);
return?tm;
}

//淘寶服務器
CString?GetTBTime(CHAR*?url)
{
HINTERNET?hSession?=?InternetOpen(_T(“UrlTest“)?INTERNET_OPEN_TYPE_PRECONFIG?NULL?NULL?0);
if?(hSession?!=?NULL)
{
HINTERNET?hHttp?=?InternetOpenUrl(hSession?url?NULL?0?INTERNET_FLAG_DONT_CACHE?0);
if?(hHttp?!=?NULL)
{
char?buffer[1024];
DWORD?bytes_read;
BOOL?b;
do
{
b?=?InternetReadFile(hHttp?buffer?1024?-?1?&bytes_read);
}?while?(bytes_read?!=?0);

//完整字符串
CString?tm;
tm.Format(“%s“?buffer);

//查找截取
int?n?=?tm.ReverseFind(‘}‘);
CString?tm2?=?tm.Mid(n?-?15?13);

//時間戳轉換
USES_CONVERSION;
char?*str?=?T2A(tm2.GetBuffer(0));
long?long?time;
sscanf(str?“%I64d“?&time);
CString?Ctm?=?MillSecond2LocalTime(time?8);
return?Ctm;

InternetCloseHandle(hHttp);
hHttp?=?NULL;
}
InternetCloseHandle(hSession);

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-04-30?13:07??GetNetTime\
?????文件????????4764??2019-04-30?13:07??GetNetTime\GetNetTime.cpp
?????文件??????????39??2019-04-30?09:26??GetNetTime\GetNetTime.h
?????文件????????2642??2019-04-30?09:26??GetNetTime\GetNetTime.rc
?????文件????????4795??2019-04-30?11:31??GetNetTime\GetNetTime.vcxproj
?????文件????????1638??2019-04-30?09:26??GetNetTime\GetNetTime.vcxproj.filters
?????文件????????1997??2019-04-30?09:26??GetNetTime\ReadMe.txt
?????文件?????????393??2019-04-30?09:26??GetNetTime\Resource.h
?????文件?????????216??2019-04-30?09:26??GetNetTime\stdafx.cpp
?????文件?????????899??2019-04-30?09:26??GetNetTime\stdafx.h
?????文件?????????236??2019-04-30?09:26??GetNetTime\targetver.h

評論

共有 條評論