I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 0.00
sub units 35.73
+
0
UnitsDate

date str

Returns a date formatted according to a given format string.
Controller: CodeCogs

Dependents

Info

Interface

C++
Excel

Date Str

 
char*date_strchar*Format
doubleDate = -1 )
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.

Fills the string based on the given format, date and region

For convenience, the format characters have been arranged by category.

Year format specifiers
Option Description Examples
L Whether it's a leap year. 1 if it is a leap year, 0 otherwise.
Y A full numeric representation of a year, 4 digits. If needed, BC will be suffixed. 4713BC, 1999, 2005
y A two digit representation of a year. If needed, BC will be suffixed. 13BC, 99 or 05

Month format specifiers
Option Description Examples
F A full textual representation of a month. Jan through Dec
m Numeric representation of a month, with leading zeros. 01 through 12
M A short textual representation of a month consisting of three letters. Jan through Dec
n Numeric representation of a month, without leading zeros. 1 through 12
t Number of days in the given month. 28 through 31

Day format specifiers
Option Description Examples
d Day of the month, 2 digits with leading zeros. 01 through 31
j Day of the month without leading zeros. 1 through 31
S English ordinal suffix for the day of the month, 2 characters. Works well with j st, nd, rd or th
z The day of the year (starting from 0). 0 through 365

Week format specifiers
Option Description Examples
D A textual representation of a day, three letters. Sun through Sat
l (lowercase 'L') A full textual representation of the day of the week. Sunday through Saturday
w Numeric representation of the day of the week. 0 (for Sunday) through 6 (for Saturday)
W ISO-8601 week number of year, weeks starting on Monday. 42

Time format specifiers
Option Description Examples
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
B Swatch Internet time 000 through 999
g 12-hour format of an hour without leading zeros. 1 through 12
G 24-hour format of an hour without leading zeros. 0 through 23
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros. 00 through 23
i Minutes with leading zeros. 00 to 59
s Seconds, with leading zeros. 00 through 59
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1112053296

Timezone related specifiers
Option Description Examples
I (uppercase 'i') Whether or not the date is in daylights savings time. 1 if Daylight Savings Time, 0 otherwise.
O Difference to Greenwich time (GMT) in hours. +0200 , -1300
T Timezone setting of this machine. EST, MDT
Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 43200

Standard format specifiers
Option Description Examples
c ISO 8601 date 2005-03-29T00:47:51+0100
r RFC 2822 formatted date Tue, 29 Mar 2005 00:47:51 +0100

Parameters

formatConstant
dt[in] The date and time to use
region[in] The current region

Authors

Keith Athaide

Warning

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

#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

DateDefault Value = -1)

Returns

The formatted string

Authors

Keith Athaide
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.