Home > atmlab > time > unixsecs2date.m

unixsecs2date

PURPOSE ^

UNIXSECS2DATE Number of seconds since 00:00:00 1 January 1970 to date.

SYNOPSIS ^

function [year, month, day, hour, minute, second] = unixsecs2date(secs)

DESCRIPTION ^

UNIXSECS2DATE Number of seconds since 00:00:00 1 January 1970 to date.

   [YEAR, MONTH, DAY, HOUR, MINUTE, SECOND] = UNIXSECS2DATE(SECS) returns
   the Gregorian calendar date (year, month, day, hour, minute, and second)
   corresponding to given number of seconds since 00:00:00 1 January 1970.

   Any missing MONTH or DAY will be replaced by ones.  Any missing HOUR,
   MINUTE or SECOND will be replaced by zeros.  If no date is specified,
   the current date and time is used.

   In UNIX, the smallest time unit is a signed 32-bit integer counting the
   number of seconds since 00:00:00 1 January 1970.  The range is from
   1901-12-13 20:45:52, when the number of seconds is 2^31-1, to 2038-01-19
   03:14:07, when the number of seconds is 2^31.

   This function is compatible but the number of seconds is not limited to
   a 32-bit integer, any MATLAB double precision number may be used.  Also,
   fractional seconds are allowed.

   See also DATE2UNIXSECS.
   $Id: unixsecs2date.m 8345 2013-04-17 18:16:40Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

unixsecs2date.m

SOURCE CODE ^

0001 function [year, month, day, hour, minute, second] = unixsecs2date(secs)
0002 %UNIXSECS2DATE Number of seconds since 00:00:00 1 January 1970 to date.
0003 %
0004 %   [YEAR, MONTH, DAY, HOUR, MINUTE, SECOND] = UNIXSECS2DATE(SECS) returns
0005 %   the Gregorian calendar date (year, month, day, hour, minute, and second)
0006 %   corresponding to given number of seconds since 00:00:00 1 January 1970.
0007 %
0008 %   Any missing MONTH or DAY will be replaced by ones.  Any missing HOUR,
0009 %   MINUTE or SECOND will be replaced by zeros.  If no date is specified,
0010 %   the current date and time is used.
0011 %
0012 %   In UNIX, the smallest time unit is a signed 32-bit integer counting the
0013 %   number of seconds since 00:00:00 1 January 1970.  The range is from
0014 %   1901-12-13 20:45:52, when the number of seconds is 2^31-1, to 2038-01-19
0015 %   03:14:07, when the number of seconds is 2^31.
0016 %
0017 %   This function is compatible but the number of seconds is not limited to
0018 %   a 32-bit integer, any MATLAB double precision number may be used.  Also,
0019 %   fractional seconds are allowed.
0020 %
0021 %   See also DATE2UNIXSECS.
0022 %   $Id: unixsecs2date.m 8345 2013-04-17 18:16:40Z gerrit $
0023 
0024 %   Author:      Peter J. Acklam
0025 %   Time-stamp:  2003-01-14 21:32:11 +0100
0026 %   E-mail:      pjacklam@online.no
0027 %   URL:         http://home.online.no/~pjacklam
0028 
0029    narginchk(1, 1);
0030 
0031 if isscalar(secs)
0032    dv = datevec(addtodate(datenum(1970, 1, 1, 0, 0, 0), secs, 'second'));
0033    C = num2cell(dv);
0034    [year, month, day, hour, minute, second] = deal(C{:});
0035 else
0036    [year, month, day, hour, minute, second] ... 
0037                = jd2date(double(secs) / 86400 + date2jd(1970, 1, 1)); 
0038 end
0039 
0040 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005