现在实在闲的荒~又懒的利用休息时间改公司的工作需要的程序~就告诉你一个经验~也许你以后在VB中上处理时间可以用的上~当初我也是遇上时间处理问题搞的焦头烂额VB中只有一个~偏偏现在可用~说实在那个真的只是好看用~VB中对时间处理个人感觉没C语言来的丰富~所以用上的API记得好像是GteSystemTime取得一串长整数~来源网路查都有~但是这组长整数VB中也无法处理~一开始是硬做~写了几百行~最后即将成功时碰上了润年的问题卡了很久~那时光时实现VB中对格林威治时间的处理让我学到不少东西~最后学长出马了~淡淡的说一句~让我来做~十行内就搞定~然后又多学到了~原来C语言内建将格林威治时间转成现在时间的功能~还可以分时区~所以用C写了支的DLL档~再用VB中去呼叫来用~真的十行内搞定~
VC - DLL部分~
程序代码:
// TransformTime.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include <time.h>
#include <string.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
//------------------------------------------------------------------------------------------------------------------//
int _stdcall TimeTrans(long lngtime, int* Rsp)
{
struct tm *ptr;
ptr=localtime(&lngtime);
Rsp[0] = ptr->tm_year -100+2000;
Rsp[1] = ptr->tm_mon +1;
Rsp[2] = ptr->tm_mday ;
Rsp[3] = ptr->tm_hour -8 ; //这是时区问题
Rsp[4] = ptr->tm_min ;
Rsp[5] = ptr->tm_sec ;
return 0;
}
//------------------------------------------------------------------------------------------------------------------//
int _stdcall TimeTrans_ed(int I_year, int I_mon, int I_day, int I_hour, int I_min, int I_sec, int* Date_show)
{
time_t n;
//int n;
struct tm t1;
t1.tm_sec = I_sec;
t1.tm_min = I_min;
t1.tm_hour = I_hour+8; //这是时区问题
t1.tm_mday = I_day;
t1.tm_mon = I_mon-1;
t1.tm_year = I_year+100-2000;
n = mktime(&t1);
//*Date_show=n;
return n;
}
我编译成TransformTime.dll~然后用VB中去呼叫他来用~
VB
程序代码:
Private Declare Function TimeTrans Lib "TransformTime.dll" (ByVal a As Long, ByRef Date_show As Long) As Integer
Private Declare Function TimeTrans_ed Lib "TransformTime.dll" (ByVal a As Integer, ByVal b As Integer, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByRef Date_show As Long) As Long
Private Function Transformed_Time(ByVal YY As Integer, ByVal Mo As Integer, ByVal DD As Integer, ByVal HH As Integer, ByVal Mi As Integer, ByVal SS As Integer) As Long
Dim a As Integer
Dim Date_show() As Long
ReDim Date_show(0)
a = TimeTrans_ed(YY, Mo, DD, HH, Mi, SS, Date_show(0))
Transformed_Time = Date_show(0)
End Function
Private Function Transform_Time(ByVal AA As Long) As String
Dim a As Integer
Dim Date_show(6) As Long
a = TimeTrans(AA, Date_show(0))
Transform_Time = Date_show(0) & "/" & Date_show(1) & "/" & Date_show(2) & " " & Date_show(3) & ":" & Date_show(4) & ":" & Date_show(5)
End Function
Form調用時
Date_Setup = Transformed_Time(CInt(T_Buff(0)), CInt(T_Buff(1)), CInt(T_Buff(2)), (CInt(T_Buff(3))), CInt(T_Buff(4)), CInt(T_Buff(5)))
因为这是STDF转档程序~所以是十六进位转ASCII的~一个转过来一个是转过去~时间和长整数互转~简单吧~VB + C = 天下无敌
P.S STDF网路上查都有~据说能将他的分析程序写出来~都卖上百万的~若说字串处理是VB中的天下~但是一旦到了非十进位档处理~那C就是专业级的了~相反你用C处理字串~如果不用的CString类~你会哭~
[
本帖最后由 wube 于 2011-5-8 20:16 编辑 ]