FUNCTION
date_str
Returns a date formatted according to a given format string.
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 AMExample 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
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.