Share via


Função StrFromTimeIntervalA (shlwapi.h)

Converte um intervalo de tempo, especificado em milissegundos, em uma cadeia de caracteres.

Sintaxe

int StrFromTimeIntervalA(
  [out] PSTR  pszOut,
        UINT  cchMax,
        DWORD dwTimeMS,
        int   digits
);

Parâmetros

[out] pszOut

Tipo: PTSTR

Um ponteiro para um buffer que, quando essa função retorna com êxito, recebe o número convertido.

cchMax

Tipo: UINT

O tamanho do pszOut, em caracteres. Se cchMax estiver definido como zero, StrFromTimeInterval retornará o tamanho mínimo do buffer de caracteres necessário para manter a cadeia de caracteres convertida. Nesse caso, pszOut não conterá a cadeia de caracteres convertida.

dwTimeMS

Tipo: DWORD

O intervalo de tempo, em milissegundos.

digits

Tipo: int

O número máximo de dígitos significativos a serem representados no pszOut. Alguns exemplos incluem:

dwTimeMS dígitos pszOut
34000 3 34 s
34000 2 34 s
34000 1 30 s
74000 3 1 min 14 s
74000 2 1 min 10 s
74000 1 1 minuto

Valor retornado

Tipo: int

Retorna o número de caracteres em pszOut, excluindo o caractere NULL de terminação.

Comentários

O valor de tempo retornado em pszOut sempre estará no formato hh horas mm minutos ss segundos . Os tempos que excedem vinte e quatro horas não são convertidos em dias ou meses. Frações de segundos são ignoradas.

Exemplos

#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

Observação

O cabeçalho shlwapi.h define StrFromTimeInterval como um alias que seleciona automaticamente a versão ANSI ou Unicode dessa função com base na definição da constante de pré-processador UNICODE. Misturar o uso do alias neutro de codificação com código que não seja neutro em codificação pode levar a incompatibilidades que resultam em erros de compilação ou de runtime. Para obter mais informações, consulte Convenções para protótipos de função.

Requisitos

   
Cliente mínimo com suporte Windows 2000 Professional, Windows XP [somente aplicativos da área de trabalho]
Servidor mínimo com suporte Windows 2000 Server [somente aplicativos da área de trabalho]
Plataforma de Destino Windows
Cabeçalho shlwapi.h
Biblioteca Shlwapi.lib
DLL Shlwapi.dll (versão 4.71 ou posterior)