strFromTimeIntervalA 函数 (shlwapi.h)
将时间间隔(以毫秒为单位)转换为字符串。
语法
int StrFromTimeIntervalA(
[out] PSTR pszOut,
UINT cchMax,
DWORD dwTimeMS,
int digits
);
参数
[out] pszOut
类型: PTSTR
指向缓冲区的指针,当此函数成功返回时,该缓冲区接收转换的数字。
cchMax
类型: UINT
pszOut 的大小(以字符为单位)。 如果 cchMax 设置为零, StrFromTimeInterval 将返回保存转换后的字符串所需的字符缓冲区的最小大小。 在这种情况下, pszOut 将不包含转换后的字符串。
dwTimeMS
类型:DWORD
时间间隔(以毫秒为单位)。
digits
类型: int
在 pszOut 中表示的最大有效位数。 下面是一些示例:
dwTimeMS | 位数 | pszOut |
---|---|---|
34000 | 3 | 34 秒 |
34000 | 2 | 34 秒 |
34000 | 1 | 30 秒 |
74000 | 3 | 1 分 14 秒 |
74000 | 2 | 1 分 10 秒 |
74000 | 1 | 1 分钟 |
返回值
类型: int
返回 pszOut 中的字符数,不包括终止 NULL 字符。
注解
pszOut 中返回的时间值将始终以 hh 小时毫米秒秒的形式表示。 超过 24 小时的时间不会转换为天或月。 忽略秒的小数部分。
示例
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
void main(void)
{
char TimeString[256];
char *pszOut;
pszOut = TimeString;
cout << "The return value from the call to"
<< "\nthe function StrFromTimeInterval will"
<< "\nreturn the number of elements in the buffer: " << endl;
cout << "\nThe return from StrFromTimeInterval is "
<< StrFromTimeInterval(pszOut,30, 34000,30);
cout << "\nThe contents of the TimeString Buffer " << pszOut << endl;
cout << "The return from StrFromTimeInterval is "
<< StrFromTimeInterval(pszOut,30, 74000,3);
cout << "\nThe contents of the TimeString Buffer " << pszOut << endl;
cout << "The return from StrFromTimeInterval is "
<< StrFromTimeInterval(pszOut,30, 74000,2);
cout << "\nThe contents of the TimeString Buffer " << pszOut << endl;
cout << "The return from StrFromTimeInterval is "
<< StrFromTimeInterval(pszOut,30, 74000,1)
<< "\nThe contents of the TimeString Buffer " << pszOut << endl;
}
OUTPUT:
- - - - -
The return value from the call to
the function StrFromTimeInterval will
return the number of elements in the buffer:
The return from StrFromTimeInterval is 7
The contents of the TimeString Buffer 34 sec
The return from StrFromTimeInterval is 13
The contents of the TimeString Buffer 1 min 14 sec
The return from StrFromTimeInterval is 13
The contents of the TimeString Buffer 1 min 10 sec
The return from StrFromTimeInterval is 6
The contents of the TimeString Buffer 1 min
注意
shlwapi.h 标头将 StrFromTimeInterval 定义为别名,该别名根据 UNICODE 预处理器常量的定义自动选择此函数的 ANSI 或 Unicode 版本。 将非特定编码别名与非非特定编码的代码混合使用可能会导致不匹配,从而导致编译或运行时错误。 有关详细信息,请参阅 函数原型的约定。
要求
最低受支持的客户端 | Windows 2000 专业版、Windows XP [仅限桌面应用] |
最低受支持的服务器 | Windows 2000 Server [仅限桌面应用] |
目标平台 | Windows |
标头 | shlwapi.h |
Library | Shlwapi.lib |
DLL | Shlwapi.dll (4.71 或更高版本) |