{"id":311,"date":"2012-02-22T00:00:00","date_gmt":"2012-02-22T00:00:00","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2012\/02\/22\/understanding-epoch-unix-timestamp\/"},"modified":"2017-12-27T17:51:07","modified_gmt":"2017-12-27T17:51:07","slug":"understanding-epoch-unix-timestamp","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/understanding-epoch-unix-timestamp\/","title":{"rendered":"How to Understand Epoch &#038; Unix Timestamp | Epoch Converter"},"content":{"rendered":"<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3849 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2012\/02\/epoch-unix-timestamp.png\" alt=\"epoch-unix-timestamp\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2012\/02\/epoch-unix-timestamp.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2012\/02\/epoch-unix-timestamp-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/h2>\n<h2>What is epoch time?<\/h2>\n<p>The <strong>Unix epoch<\/strong> (or <strong>Unix time<\/strong> or <strong>POSIX time<\/strong> or <strong>Unix timestamp<\/strong>) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC\/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1\/1\/1970), but &#8216;epoch&#8217; is often used as a synonym for &#8216;Unix time&#8217;. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td><strong>Human readable time<\/strong><\/td>\n<td align=\"right\"><strong>Seconds<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1 hour<\/td>\n<td align=\"right\">3600 seconds<\/td>\n<\/tr>\n<tr>\n<td>1 day<\/td>\n<td align=\"right\">86400 seconds<\/td>\n<\/tr>\n<tr>\n<td>1 week<\/td>\n<td align=\"right\">604800 seconds<\/td>\n<\/tr>\n<tr>\n<td>1 month (30.44 days)<\/td>\n<td align=\"right\">2629743 seconds<\/td>\n<\/tr>\n<tr>\n<td>1 year (365.24 days)<\/td>\n<td align=\"right\">31556926 seconds<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>How to get the current epoch time in &#8230;<\/h2>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td><strong>Perl<\/strong><\/td>\n<td>time<\/td>\n<\/tr>\n<tr>\n<td><strong>PHP<\/strong><\/td>\n<td>time()<\/td>\n<\/tr>\n<tr>\n<td><strong>Ruby<\/strong><\/td>\n<td>Time.now (or Time.new). To display the epoch: Time.now.to_i<\/td>\n<\/tr>\n<tr>\n<td><strong>Python<\/strong><\/td>\n<td>import time first, then time.time()<\/td>\n<\/tr>\n<tr>\n<td><strong>Java<\/strong><\/td>\n<td>long epoch = System.currentTimeMillis()\/1000;<\/td>\n<\/tr>\n<tr>\n<td><strong>Microsoft .NET C#<\/strong><\/td>\n<td>epoch = (DateTime.Now.ToUniversalTime().Ticks &#8211; 621355968000000000) \/ 10000000;<\/td>\n<\/tr>\n<tr>\n<td><strong>VBScript\/ASP<\/strong><\/td>\n<td>DateDiff(&#8220;s&#8221;, &#8220;01\/01\/1970 00:00:00&#8221;, Now())<\/td>\n<\/tr>\n<tr>\n<td><strong>R<\/strong><\/td>\n<td>as.numeric(Sys.time())<\/td>\n<\/tr>\n<tr>\n<td><strong>Erlang<\/strong><\/td>\n<td>calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time( now()))-719528*24*3600.<\/td>\n<\/tr>\n<tr>\n<td><strong>MySQL<\/strong><\/td>\n<td>SELECT unix_timestamp(now()) <a href=\"http:\/\/www.epochconverter.com\/programming\/mysql-from-unixtime.php\" target=\"_blank\" rel=\"noopener\">More info (+ negative epochs)<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>PostgreSQL<\/strong><\/td>\n<td>SELECT extract(epoch FROM now());<\/td>\n<\/tr>\n<tr>\n<td><strong>Oracle PL\/SQL<\/strong><\/td>\n<td>SELECT (SYSDATE &#8211; TO_DATE(&#8217;01\/01\/1970 00:00:00&#8242;, &#8216;MM-DD-YYYY HH24:MI:SS&#8217;)) *<br \/>\n24 * 60 * 60 FROM DUAL<\/td>\n<\/tr>\n<tr>\n<td><strong>SQL Server<\/strong><\/td>\n<td>SELECT DATEDIFF(s, &#8216;1970-01-01 00:00:00&#8217;, GETUTCDATE())<\/td>\n<\/tr>\n<tr>\n<td><strong>JavaScript<\/strong><\/td>\n<td>Math.round(new Date().getTime()\/1000.0) getTime() returns time in milliseconds.<\/td>\n<\/tr>\n<tr>\n<td><strong>Tcl\/Tk<\/strong><\/td>\n<td>clock seconds<\/td>\n<\/tr>\n<tr>\n<td><strong>Unix\/Linux Shell<\/strong><\/td>\n<td>date +%s<\/td>\n<\/tr>\n<tr>\n<td><strong>PowerShell<\/strong><\/td>\n<td>Get-Date -UFormat &#8220;%s&#8221; Produces: 1279152364.63599<\/td>\n<\/tr>\n<tr>\n<td><strong>Other OS&#8217;s <\/strong><\/td>\n<td>Command line: perl -e &#8220;print time&#8221; (If Perl is installed on your system)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Convert from human readable date to epoch<\/h2>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td><strong>Perl<\/strong><\/td>\n<td>Use the <a href=\"http:\/\/www.epochconverter.com\/programming\/functions-perl.php\" target=\"_blank\" rel=\"noopener\">Perl Epoch routines<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>PHP<\/strong><\/td>\n<td>mktime(<em>hour<\/em>, <em>minute<\/em>, <em>second<\/em>, <em>month<\/em>, <em>day<\/em>, <em>year<\/em>) <a href=\"http:\/\/www.php.net\/mktime\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>Ruby<\/strong><\/td>\n<td>Time.local(<em>year<\/em>, <em>month<\/em>, <em>day<\/em>, <em>hour<\/em>, <em>minute<\/em>, <em>second<\/em>, <em>usec<\/em> ) (or Time.gm for GMT\/UTC input). To display add .to_i<\/td>\n<\/tr>\n<tr>\n<td><strong>Python<\/strong><\/td>\n<td>import time first, then int(time.mktime(time.strptime(&#8216;2000-01-01 12:34:00&#8217;, &#8216;%Y-%m-%d %H:%M:%S&#8217;))) &#8211; time.timezone<\/td>\n<\/tr>\n<tr>\n<td><strong>Java<\/strong><\/td>\n<td>long epoch = new java.text.SimpleDateFormat (&#8220;MM\/dd\/yyyy HH:mm:ss&#8221;).parse(&#8220;01\/01\/1970 01:00:00&#8221;).getTime();<\/td>\n<\/tr>\n<tr>\n<td><strong>VBScript\/ASP<\/strong><\/td>\n<td>DateDiff(&#8220;s&#8221;, &#8220;01\/01\/1970 00:00:00&#8221;, <em>time field<\/em>) <a href=\"http:\/\/www.epochconverter.com\/programming\/#asp\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>C<\/strong><\/td>\n<td>Use the <a href=\"http:\/\/www.epochconverter.com\/programming\/functions-c.php\" target=\"_blank\" rel=\"noopener\">C Epoch Converter routines<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>R<\/strong><\/td>\n<td>as.numeric(as.POSIXct(&#8220;MM\/dd\/yyyy HH:mm:ss&#8221;, origin=&#8221;1970-01-01&#8243;))<\/td>\n<\/tr>\n<tr>\n<td><strong>MySQL<\/strong><\/td>\n<td>SELECT unix_timestamp(<em>time<\/em>) Time format: YYYY-MM-DD HH:MM:SS or YYMMDD or YYYYMMDD<br \/>\n<a href=\"http:\/\/www.epochconverter.com\/programming\/mysql-from-unixtime.php\" target=\"_blank\" rel=\"noopener\">More on using Epoch timestamps with MySQL<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>PostgreSQL<\/strong><\/td>\n<td>SELECT extract(epoch FROM date(&#8216;2000-01-01 12:34&#8217;));<br \/>\nWith timestamp: SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE &#8216;2001-02-16 20:38:40-08&#8217;);<br \/>\nWith interval: SELECT EXTRACT(EPOCH FROM INTERVAL &#8216;5 days 3 hours&#8217;);<\/td>\n<\/tr>\n<tr>\n<td><strong>SQL Server<\/strong><\/td>\n<td>SELECT DATEDIFF(s, &#8216;1970-01-01 00:00:00&#8217;, <em>time field<\/em>)<\/td>\n<\/tr>\n<tr>\n<td><strong>JavaScript<\/strong><\/td>\n<td>Use the <a href=\"http:\/\/www.epochconverter.com\/programming\/#javascript\" target=\"_blank\" rel=\"noopener\">JavaScript Date object<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>Unix\/Linux Shell<\/strong><\/td>\n<td>date +%s -d&#8221;Jan 1, 1980 00:00:01&#8243; Replace &#8216;-d&#8217; with &#8216;-ud&#8217; to input in GMT\/UTC time.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Convert from epoch to human readable date<\/h2>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td><strong>Perl<\/strong><\/td>\n<td>Use the <a href=\"http:\/\/www.epochconverter.com\/programming\/functions-perl.php\" target=\"_blank\" rel=\"noopener\">Perl Epoch routines<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>PHP<\/strong><\/td>\n<td>date(<em>output format<\/em>, <em>epoch<\/em>); Output format example: &#8216;r&#8217; = RFC 2822 date <a href=\"http:\/\/nl2.php.net\/date\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>Ruby<\/strong><\/td>\n<td>Time.at(<em>epoch<\/em>)<\/td>\n<\/tr>\n<tr>\n<td><strong>Python<\/strong><\/td>\n<td>import time first, then time.strftime(&#8220;%a, %d %b %Y %H:%M:%S +0000&#8221;, time.localtime(<em>epoch<\/em>)) Replace time.localtime with time.gmtime for GMT time. <a href=\"http:\/\/docs.python.org\/lib\/module-time.html\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>Java<\/strong><\/td>\n<td>String date = new java.text.SimpleDateFormat(&#8220;MM\/dd\/yyyy HH:mm:ss&#8221;).format(new java.util.Date (<em>epoch<\/em>*1000));<\/td>\n<\/tr>\n<tr>\n<td><strong>VBScript\/ASP<\/strong><\/td>\n<td>DateAdd(&#8220;s&#8221;, <em>epoch<\/em>, &#8220;01\/01\/1970 00:00:00&#8221;) <a href=\"http:\/\/www.epochconverter.com\/programming\/#asp\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>C<\/strong><\/td>\n<td>Use the <a href=\"http:\/\/www.epochconverter.com\/programming\/functions-c.php\" target=\"_blank\" rel=\"noopener\">C Epoch Converter routines<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>R<\/strong><\/td>\n<td>as.POSIXct(epoch, origin=&#8221;1970-01-01&#8243;)<\/td>\n<\/tr>\n<tr>\n<td><strong>MySQL<\/strong><\/td>\n<td>from_unixtime(<em>epoch<\/em>, <em>optional output format<\/em>) The default output format is YYY-MM-DD HH:MM:SS <a href=\"http:\/\/www.epochconverter.com\/programming\/mysql-from-unixtime.php\" target=\"_blank\" rel=\"noopener\">more &#8230;<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>PostgreSQL<\/strong><\/td>\n<td>PostgreSQL version 8.1 and higher: SELECT to_timestamp(<em>epoch<\/em>); <a href=\"http:\/\/www.postgresql.org\/docs\/8.1\/static\/functions-formatting.html\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a> Older versions: SELECT TIMESTAMP WITH TIME ZONE &#8216;epoch&#8217; + <em>epoch<\/em> * INTERVAL &#8216;1 second&#8217;;<\/td>\n<\/tr>\n<tr>\n<td><strong>Oracle PL\/SQL<\/strong><\/td>\n<td>SELECT to_date(&#8217;01-JAN-1970&#8242;,&#8217;dd-mon-yyyy&#8217;)+(1326357743\/60\/60\/24) from dual<br \/>\nReplace 1326357743 with epoch.<\/td>\n<\/tr>\n<tr>\n<td><strong>SQL Server<\/strong><\/td>\n<td>DATEADD(s, <em>epoch<\/em>, &#8216;1970-01-01 00:00:00&#8217;)<\/td>\n<\/tr>\n<tr>\n<td><strong>Microsoft Excel<\/strong><\/td>\n<td>=(A1 \/ 86400) + 25569 Format the result cell for date\/time, the result will be in GMT time (A1 is the cell with the epoch number). For other time zones: =((A1 +\/- <a href=\"http:\/\/www.epochconverter.com\/epoch\/timezones.php\" target=\"_blank\" rel=\"noopener\">time zone adjustment<\/a>) \/ 86400) + 25569.<\/td>\n<\/tr>\n<tr>\n<td><strong>Crystal Reports<\/strong><\/td>\n<td>DateAdd(&#8220;s&#8221;, {EpochTimeStampField}-14400, #1\/1\/1970 00:00:00#) -14400 used for Eastern Standard Time. See <a href=\"http:\/\/www.epochconverter.com\/epoch\/timezones.php\" target=\"_blank\" rel=\"noopener\">Time Zones<\/a>.<\/td>\n<\/tr>\n<tr>\n<td><strong>JavaScript<\/strong><\/td>\n<td>Use the <a href=\"http:\/\/www.epochconverter.com\/programming\/#javascript\" target=\"_blank\" rel=\"noopener\">JavaScript Date object<\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>Tcl\/Tk<\/strong><\/td>\n<td>clock format 1325376000 <a href=\"http:\/\/www.tcl.tk\/man\/tcl8.4\/TclCmd\/clock.htm\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.epochconverter.com\/img\/icons\/info.png\" alt=\"More info\" width=\"16\" height=\"16\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><strong>Unix\/Linux Shell<\/strong><\/td>\n<td>date -d @1190000000 Replace 1190000000 with your epoch, needs recent version of &#8216;date&#8217;. Replace &#8216;-d&#8217; with &#8216;-ud&#8217; for GMT\/UTC time.<\/td>\n<\/tr>\n<tr>\n<td><strong>PowerShell<\/strong><\/td>\n<td>Function get-epochDate ($epochDate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]&#8217;1\/1\/1970&#8242;).AddSeconds($epochDate)) }, then use: get-epochDate 1279152364. Works for Windows PowerShell v1 and v2<\/td>\n<\/tr>\n<tr>\n<td><strong>Other OS&#8217;s<\/strong><\/td>\n<td>Command line: perl -e &#8220;print scalar(localtime(<em>epoch<\/em>))&#8221; (If Perl is installed) Replace &#8216;localtime&#8217; with &#8216;gmtime&#8217; for GMT\/UTC time.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Reference<\/strong><\/p>\n<p><a href=\"http:\/\/www.epochconverter.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.epochconverter.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is epoch time? The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC\/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1\/1\/1970), but &#8216;epoch&#8217; is often used as a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3849,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[2587,2588,2580,2582,2592,2583,2589,2590,2591,2581,2579,2586,169,2593,2584,2585],"class_list":["post-311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-about-epoch-timestamp","tag-about-unix-timestamp","tag-epoch","tag-epoch-and-unix","tag-epoch-converter","tag-epoch-time","tag-introduction-epoch-timestamp","tag-introduction-unix-timestamp","tag-overview-epoch-unix-timestamp","tag-timestamp","tag-understand","tag-understand-epoch-unix-timestamp","tag-unix","tag-unix-timestamp","tag-what-is-epoch-time","tag-what-is-unix-time"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":4334,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions\/4334"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3849"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}