Returns a date formatted according to a given format string.

You're viewing an older version of this page (#126). View the current version.

View versions (1)

Interface

#include <codecogs/units/date/date_str.h>

using namespace Units::Date;

Returns a string formatted according to the given format string using the given integer timestamp or the current local time if no timestamp is given.

\copydoc DateString DateString::fill

The string returned by this function is dynamically allocated and it is necessary for the calling code to deallocate it with a delete statement otherwise a memory leak will occur.

Example 1

#include <iostream>
#include <codecogs/units/date/date_str.h>

int main()
{
  char* pDateStr = Units::Date::date_str("l dS of F Y h:i:s A");
  std::cout<<pDateStr;
  delete[] pDateStr;
  return 0;
}

Output:

Tuesday 29th of March 2005 03:27:48 AM

Example 2

Any of the format string examples shown above can be used. Additionally a timestamp could be specified.

#include <iostream>
#include <codecogs/units/date/date_str.h>

int main()
{
  char* pDateStr = Units::Date::date_str("j, n, Y ", 2123011);
  std::cout<<pDateStr;

  delete[] pDateStr;
  return 0;
}

Output:

4, 7, 1100

Parameters

Date
Default Value = -1)

Returns

The formatted string
GPL Licence — free for non commercial use. See Licence details.