GXIntlStrFtime

size_t GXIntlStrFtime(HINSTANCE nResourceHandle, UINT nStrFTimeResourceID, LPTSTR str, size_t maxs, LPCTSTR fmt, const struct tm* tm);

nResourceHandle

An HINSTANCE handle where the default resources of the application are loaded. Set this value to AfxGetResourceHandle( ).

nStrFTimeResourceID

Specifies the first resource id in your .RC file with abbreviations for the day names (GX_IDS_TIME_ADAY1). The ids must be numbered consecutively. GX_IDS_TIME_ADAY1 represents Sunday.

str

Points to a buffer for the output string.

maxs

Specifies the maximum size (including the terminal NUL character) for the output string.

fmt

Points to the format-control string with tokens. A percent sign (%) indicates a token.

tm

tm data structure.

Return Value

If the total number of characters is less than maxs, the maximum size, GXIntlStrFtime returns the number of characters placed in the string, including the NUL character. If the total number of characters, including the terminating NUL character, exceeds maxs, the function returns 0 and the contents of the string are indeterminate.

Remarks

The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign (%). Characters that do not begin with % are copied unchanged to string. The formatting codes for strftime are listed below:

  • %aAbbreviated weekday name

  • %AFull weekday name

  • %bAbbreviated month name

  • %BFull month name

  • %cDate and time representation appropriate for locale

  • %dDay of month as decimal number (01 - 31)

  • %HHour in 24-hour format (00 - 23)

  • %IHour in 12-hour format (01 - 12)

  • %jDay of year as decimal number (001 - 366)

  • %mMonth as decimal number (01 - 12)

  • %MMinute as decimal number (00 - 59)

  • %pA.M./P.M. indicator for 12-hour clock

  • %SSecond as decimal number (00 - 59)

  • %UWeek of year as decimal number, with Sunday as first day of week (00 - 51)

  • %wWeekday as decimal number (0 - 6; Sunday is 0)

  • %WWeek of year as decimal number, with Monday as first day of week (00 - 51)

  • %xDefault Date representation

  • %XDefault Time representation

  • %yYear without century, as decimal number (00 - 99)

  • %YYear with century, as decimal number

  • %z, %ZTime-zone name or abbreviation; no characters if time zone is unknown

  • %%Percent sign

See the example for the resource file entries.

You have to pass the time information with tm. The actual time is for example:

time_t ti = time(NULL);

struct tm* ptmTemp = localtime(&ti);

GXIntlStrFtime(AfxGetResourceHandle( ), GX_IDS_TIME_ADAY1,

szBuffer, sizeof(szBuffer), "%H:%M", ptmTemp);

The grid-component calls GXIntlStrFtime when drawing Headers or Footers with nStrFTimeResourceIDset to GX_IDS_TIME_ADAY1. If you don’t want English dates and times, you can change the resources. See the example. It is important that the first name be GX_IDS_TIME_ADAY1 because the grid-component expects this. All other resources must be numbered consecutively, because GXIntlStrFtime accesses the strings by loading the resource associated with the resource-id determined by adding an offset to nStrFTimeResourceID.

Note:

In 32-bit environments, GXIntlStrFtime is only supported for compatibility reasons. The 32-bit runtime library routine strftime provides the necessary functionality for displaying locale representations of date/time values. If you want to support locale representations of date/time values in 32-bit applications, you should call the C++ runtime library routine setlocale. GXIntlStrFtime will simply pass its arguments to strftime.

Example

This is an example of the resource file entries and how to call GXIntlStrFtime.

STRINGTABLE DISCARDABLE

BEGIN

GX_IDS_TIME_ADAY1 "Sun"

GX_IDS_TIME_ADAY2 "Mon"

GX_IDS_TIME_ADAY3 "Tue"

GX_IDS_TIME_ADAY4 "Wed"

GX_IDS_TIME_ADAY5 "Thu"

GX_IDS_TIME_ADAY6 "Fri"

GX_IDS_TIME_ADAY7 "Sat"

GX_IDS_TIME_DAY1 "Sunday"

GX_IDS_TIME_DAY2 "Monday"

GX_IDS_TIME_DAY3 "Tuesday"

GX_IDS_TIME_DAY4 "Wednesday"

GX_IDS_TIME_DAY5 "Thursday"

GX_IDS_TIME_DAY6 "Friday"

GX_IDS_TIME_DAY7 "Saturday"

GX_IDS_TIME_AMONTH1 "Jan"

GX_IDS_TIME_AMONTH2 "Feb"

END

STRINGTABLE DISCARDABLE

BEGIN

GX_IDS_TIME_AMONTH3 "Mar"

GX_IDS_TIME_AMONTH4 "Apr"

GX_IDS_TIME_AMONTH5 "May"

GX_IDS_TIME_AMONTH6 "Jun"

GX_IDS_TIME_AMONTH7 "Jul"

GX_IDS_TIME_AMONTH8 "Aug"

GX_IDS_TIME_AMONTH9 "Sep"

GX_IDS_TIME_AMONTH10 "Oct"

GX_IDS_TIME_AMONTH11 "Nov"

GX_IDS_TIME_AMONTH12 "Dec"

GX_IDS_TIME_MONTH1 "January"

GX_IDS_TIME_MONTH2 "February"

GX_IDS_TIME_MONTH3 "March"

GX_IDS_TIME_MONTH4 "April"

GX_IDS_TIME_MONTH5 "May"

GX_IDS_TIME_MONTH6 "June"

END

STRINGTABLE DISCARDABLE

BEGIN

GX_IDS_TIME_MONTH7 "July"

GX_IDS_TIME_MONTH8 "August"

GX_IDS_TIME_MONTH9 "September"

GX_IDS_TIME_MONTH10 "October"

GX_IDS_TIME_MONTH11 "November"

GX_IDS_TIME_MONTH12 "December"

GX_IDS_TIME_DATIME "%a %b %d %H:%M:%S %Y"

GX_IDS_TIME_DATE "%a %b %d %Y"

GX_IDS_TIME_TIME "%H:%M:%S"

END

// resource.h file:

#define GX_IDS_TIME_ADAY1 52400

#define GX_IDS_TIME_ADAY2 52401

#define GX_IDS_TIME_ADAY3 52402

#define GX_IDS_TIME_ADAY4 52403

#define GX_IDS_TIME_ADAY5 52404

#define GX_IDS_TIME_ADAY6 52405

#define GX_IDS_TIME_ADAY7 52406

#define GX_IDS_TIME_DAY1 52407

#define GX_IDS_TIME_DAY2 52408

#define GX_IDS_TIME_DAY3 52409

#define GX_IDS_TIME_DAY4 52410

#define GX_IDS_TIME_DAY5 52411

#define GX_IDS_TIME_DAY6 52412

#define GX_IDS_TIME_DAY7 52413

#define GX_IDS_TIME_AMONTH1 52414

#define GX_IDS_TIME_AMONTH2 52415

#define GX_IDS_TIME_AMONTH3 52416

#define GX_IDS_TIME_AMONTH4 52417

#define GX_IDS_TIME_AMONTH5 52418

#define GX_IDS_TIME_AMONTH6 52419

#define GX_IDS_TIME_AMONTH7 52420

#define GX_IDS_TIME_AMONTH8 52421

#define GX_IDS_TIME_AMONTH9 52422

#define GX_IDS_TIME_AMONTH10 52423

#define GX_IDS_TIME_AMONTH11 52424

#define GX_IDS_TIME_AMONTH12 52425

#define GX_IDS_TIME_MONTH1 52426

#define GX_IDS_TIME_MONTH2 52427

#define GX_IDS_TIME_MONTH3 52428

#define GX_IDS_TIME_MONTH4 52429

#define GX_IDS_TIME_MONTH5 52430

#define GX_IDS_TIME_MONTH6 52431

#define GX_IDS_TIME_MONTH7 52432

#define GX_IDS_TIME_MONTH8 52433

#define GX_IDS_TIME_MONTH9 52434

#define GX_IDS_TIME_MONTH10 52435

#define GX_IDS_TIME_MONTH11 52436

#define GX_IDS_TIME_MONTH12 52437

#define GX_IDS_TIME_DATIME 52438

#define GX_IDS_TIME_DATE 52439

#define GX_IDS_TIME_TIME 52440

This examples illustrates how to call GXIntlStrFTime.

// GetCurrentTime

time_t ti = time(NULL);

struct tm* ptmTemp = localtime(&ti);

ASSERT(ptmTemp != NULL); // make sure the time has been initialized!

if (!GXIntlStrFtime(AfxGetResourceHandle( ), GX_IDS_TIME_ADAY1,

szBuffer, sizeof(szBuffer), args, ptmTemp))

szBuffer[0] = '\0';

return szBuffer;

See Also

 CGXProperties::SubstTokenText

Macros

 Class Overview |  Class Members