时间换算程序
如何实现时间换算程序?设计一个时间换算程序,要求输入小时数、分钟数和秒数后,单击“计算”按钮输出合计秒数。
2011-05-01 14:07
程序代码:
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer, d As Long
a = 0: b = 0: c = 0: d = 0
a = InputBox("Hours ?")
If a < 24 Then
d = CLng(a * 60) * 60: MsgBox d & " Seconds"
b = InputBox("Minutes ?")
If b < 60 Then
d = CLng(d + (b * 60)): MsgBox d & " Seconds"
c = InputBox("Seconds ?")
If c < 60 Then
d = CLng(d + c): MsgBox d & " Seconds"
Else
c = 0
MsgBox "Seconds Error !"
End If
Else
b = 0
MsgBox "Minutes Error !"
End If
ElseIf a = 24 Then
d = CLng(a * 60) * 60: MsgBox d & " Seconds"
Else
a = 0
MsgBox "Hours Error !"
End If
MsgBox "Hours: " & a & " + Minutes: " & b & " + Seconds: " & c & " = " & d & " Seconds"
End Sub

2011-05-01 18:43
2011-05-02 07:31
初学者表示佩服。
2011-05-08 19:28
程序代码:
// 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;
}
程序代码:
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
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)))

2011-05-08 20:07