Export (0) Print
Expand All

StrFromTimeInterval function

Converts a time interval, specified in milliseconds, to a string.

Syntax


int StrFromTimeInterval(
  _Out_  PTSTR pszOut,
  UINT cchMax,
  DWORD dwTimeMS,
  int digits
);

Parameters

pszOut [out]

Type: PTSTR

A pointer to a buffer that, when this function returns successfully, receives the converted number.

cchMax

Type: UINT

The size of pszOut, in characters. If cchMax is set to zero, StrFromTimeInterval will return the minimum size of the character buffer needed to hold the converted string. In this case, pszOut will not contain the converted string.

dwTimeMS

Type: DWORD

The time interval, in milliseconds.

digits

Type: int

The maximum number of significant digits to be represented in pszOut. Some examples are:

dwTimeMSdigitspszOut
34000334 sec
34000234 sec
34000130 sec
7400031 min 14 sec
7400021 min 10 sec
7400011 min

 

Return value

Type: int

Returns the number of characters in pszOut, excluding the terminating NULL character.

Remarks

The time value returned in pszOut will always be in the form hh hours mm minutes ss seconds. Times that exceed twenty four hours are not converted to days or months. Fractions of seconds are ignored.

Examples


#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

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 4.71 or later)

Unicode and ANSI names

StrFromTimeIntervalW (Unicode) and StrFromTimeIntervalA (ANSI)

 

 

Community Additions

ADD
Show:
© 2014 Microsoft