Timestamp generator

Value converters

Generates timestamps from strings, displays info about dates and formats them in a neat way.

This online tool shows information about a given Unix timestamps as well as converting arbitrary time string (e.g. «1 January 1999») into timestamp and formatting timestamp according to various RFC/ISO/W3C standards or by a custom format string. 

All fields are set to current time by default so feel free to roll the dice right away and see what this tool has to offer. 

H:M:S D/M/Y
Ctrl+Shift+E ↔
Ctrl+Shift+E ↔

This is relative to the above. Allowed operators are: 

  • + – / * ( ) – arithmetics and grouping;
  • . , – fractions («1.5» or «1,5» – the same);
  • spaces inside expression are allowed but ignored.

Also, shortcuts exist for (m)inute, (h)our, (d)ay and (w)eek

Examples: 

  • «+1d» (tomorrow),
  • «-1d – 1/2m» (yesterday, the same hour but half a minute ago).
Ctrl+Shift+E ↔
Ctrl+Shift+E ↔
Ctrl+Shift+E ↔
Ctrl+Shift+E ↔
Ctrl+Shift+E ↔
Ctrl+Shift+E ↔
Timestamp generator
  1. 1. DateFmt
    1. 1.1. Format strings
  2. 2. date()
    1. 2.1. Format strings
  3. 3. strftime

UNIX timestamp (or Unix time) is a number of seconds passed since 1st January 1970. As name states timestamps are mostly used in *nix systems (including Linux and FreeBSD) to represent exact date & time values. For example, number 1303578469 stands for 17:07:49, 23rd April 2011 (try it yourself).
Timestamp doesn't represent leap seconds and thus it's not a proper UTC

Technically timestamp is (usually) a signed 32-bit integer and as a consequence it's incapable of representing dates after 03:14:08 UTC on 19 January 2038 – so-called Year 2038 problem. When the value overflows the time for Unix systems using traditional signed time_t type will jump back by 68 years. 

That said, Microsoft DOS had a valid time range from 1980 untill 2099 years. 

There are other formats used to represent time. For example, Windows systems use 16-byte records to represent file times which have a wider range of years (1601 through 30827) than Unix time does (1970 through 2038 excluding negative timestamps) and is also capable of representing milliseconds. 

DateFmt 

This is a standalone PHP class – all-in-one solution for formatting date and time. It focuses on native standards and easy to read and remember format string. It also adds (by means of format string) a number of functions that do not exist in standard routines – such as relative time («3 weeks ago»). 

Full reference, as well as download section, can be found at the project's homepage here. Here most commonly used format strings are listed. 

Format strings 

Numeric format strings often have either one or two hash symbols (#) following them. One hash symbol tells that it's indeed a format string while two hash symbols also pad it with a zero if it's smaller than 10.
For year (y##) this is an exception as two hash symbols stand for 4-digit year year instead of 2-digit (y#). 

Similar idea goes for word format strings that have either one or two underscores (_) following: one underscore is required for a format string while two make it output full name instead of short (e.g. «January» instead of «Jan»). 

Example DateFmt call (see the reference): 

PHP
echo DateFmt::Format('D__, d##my');    // => Tuesday, 26/04/2011
Format string Description Examples
Full date/time
h#m and h##m National time without seconds 3:26 AM and 03:26 AM
h#ms and h##ms National time with seconds 3:26:09 AM and 03:26:09 AM
d#m and d##m National date without year 5/04 and 05/04
d#my and d##my National date with year 5/04/2011 and 05/04/2011
Date/time format strings
s# s## m# m## Second and minute with (##) and without (#) leading zeros. 0…59, 0…59
h# h## H# H## Hour in 12- and 24 hour format with (##) and without (#) leading zeros. 1…12, 0…23
d# d## mo# mo## y# y## Day, month (note: it's "mo", "m" is used to specify minutes), year with (##) and without (#) leading zeros. 1…31, 1…12, 00…99, 1970…2038
Names
d_ d__ D_ D__ Short (_) and full (__) day names in native (usually capitalized, "D") and lower-case ("d") forms. Mon … Sun, Monday … Sunday
m_ m__ M_ M__ Short (_) and full (__) month names in native (usually capitalized, "M") and lower-case ("m") forms. Jan … Dec, Jan … December
y_ y__ Native word for word "year" in short and full forms. "y.", "year"
Time ago (see AGO[] and IF[])
AGO[*] Instead of asterisk the following characters can be used (for seconds...years): s m h d w o y. 2 days ago, 8 months later
AGO-SHORT[*] A form of AGO[] that uses short word forms for more concise output. 2d ago, 8m later
AGO[*]IF-FAR[…] A conditional form of AGO[] that switches to usual formating (of Date/time above) if given date is too far. 2 days ago, 3/11/2010
AGO-SHORT[*]IF-FAR[…] A conditional form of AGO-SHORT[], similar to AGO[]IF but uses short word forms. 3h ago, 3/11/2010
AGO[*]_ Suppress ago/later words. Also works for IF as: AGO[*]IF[…]_ 2 days, 8 hours
"At"-time (see AT[])
[d#my]AT h#m Uses native language settings to output proper word form and preposition for "at". Can be combined with other functions (AGO, IF). 12/01/2011 at 7:07 PM
Posted at AT[D__, d# M__##] THe same as []AT (suffix "AT") but doesn't output the preposition – only changes word forms. This form makes sense for languages with inflexion changes like Russian. Posted at Wednesday, 12 February

Full reference to DateFmt format string is located here. 

date() 

Standard PHP function date() supports a large variety of format strings and it's fast and convenient to use – for example, to check if two dates are about the same day the following code can be used: 

PHP
date('dmy'$date1) == date('dmy'$date2)

However, when using it to format more or less complicated string there are at least 3 problems

  1. Poor to none localization – by default format strings that output a word (such as «M» for month – «January», etc.) return it in English; this can be fixed by changing current locale but it doesn't always work.
  2. The way standard format strings are (i.e. just letters in contrast with strftime, see below) prevent from putting into format string any other «human» words because they will be mistaken for format strings unless prefixed with a backslash.
  3. Format strings are hard to remember – usual formats for day or month number («d» and «m») are fine but for less used they seem to be random (for example, «z» for day of year).

Format strings 

Since date is a standard PHP function it doesn't need any external libraries and is used like this: 

PHP
echo date('d.m.y H:i');   // => 26.04.11 14:52

Format strings passed as date()'s first argument are listed below. 

Format string Description Examples
Full date/time
c ISO 8601 date 2004-02-12T15:19:21+00:00
r RFC 2822 date Thu, 21 Dec 2000 16:01:07 +0200
Day
z Day of year without leading zeros 0 1 … 365
d Day of month with leading zeros 01 02 … 31
j Day of month without leading zeros 1 2 … 31
l Full day name Monday … Sunday
D Short day name (3 letters) Mon … Sun
S English suffix for day of month (2 letters) st, nd, rd, th
w Day number for current week (0-based) 1 (Sunday), 2 (Monday) … 7 (Saturday)
N Day number for current week (1-based according to ISO-8601) 1 (Monday), 2 (Tuesday) … 7 (Sunday)
Week
W ISO-8601 week number of year (1-based; weeks start on Monday); with leading zeros. 01 02 … 42
Month
n Month number of year without leading zeros (1-based) 1 2 … 12
m Month number of year with leading zeros (1-based) 01 02 … 12
F Full month name January … December
M Short month name Jan … Dec
t Number of days in given month (1-based) 28, 29, 30, 31
Year
Y 4 digits for year 1999, 2005, 2015
y 2 digits for year 99, 05, 15
L 1 if given year is leap, 0 otherwise 1, 0
o ISO-8601 year number. This is the same as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. 1999, 2005, 2015
Hour
G 24-hour hour without leading zeros 0 1 … 23
H 24-hour hour with leading zeros 00 01 … 23
g 12-hour hour without leading zeros 1 2 … 12
h 12-hour hour with leading zeros 01 02 … 12
a Lowercase Ante Meridiem and Post Meridiem am, pm
A Uppercase Ante Meridiem and Post Meridiem AM, PM
Other time strings
i Minutes with leading zeros 00 01 … 59
s Seconds with leading zeros 00 01 … 59
U Timestamp (see time()) 1303580175
u Microseconds 654321
B Swatch Internet time 000 … 999
Timezone
e Timezone identifier UTC, GMT, Atlantic/Azores
T Timezone abbreviation EST, MDT
O Difference to GMT in hours +0200
p Difference to GMT with colon between hours and minutes +02:00
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 … 50400
I 1 if DST is in effect, 0 otherwise 1, 0

strftime 

There's another PHP function used to format date & time – strftime. It's used less often that the date function. It differs from it in the way format string is interpreted: control characters (e.g. «d» for day) are prefixed with a percent sign (%) to avoid collisions with normal word characters (which is a common problem for date). This is where its name comes from – standard printf() function also formats strings in this way. 

strftime() has the same format strings as date() with a few exceptions. 

An example of how this function is used: 

PHP
echo strftime("%d.%m.%y %H:%M"),"\n";   // => 26.04.11 15:21

You can find the list of strftime()'s format strings in the PHP manual.