Home > atmlab > time > date2unixsecs.m

date2unixsecs

PURPOSE ^

DATE2UNIXSECS Number of seconds since 00:00:00 1 January 1970.

SYNOPSIS ^

function secs = date2unixsecs(varargin)

DESCRIPTION ^

DATE2UNIXSECS Number of seconds since 00:00:00 1 January 1970.

   DATE2UNIXSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) returns the 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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

date2unixsecs.m

SOURCE CODE ^

0001 function secs = date2unixsecs(varargin)
0002 %DATE2UNIXSECS Number of seconds since 00:00:00 1 January 1970.
0003 %
0004 %   DATE2UNIXSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) returns the number
0005 %   of seconds since 00:00:00 1 January 1970.
0006 %
0007 %   Any missing MONTH or DAY will be replaced by ones.  Any missing HOUR,
0008 %   MINUTE or SECOND will be replaced by zeros.  If no date is specified,
0009 %   the current date and time is used.
0010 %
0011 %   In UNIX, the smallest time unit is a signed 32-bit integer counting the
0012 %   number of seconds since 00:00:00 1 January 1970.  The range is from
0013 %   1901-12-13 20:45:52, when the number of seconds is 2^31-1, to 2038-01-19
0014 %   03:14:07, when the number of seconds is 2^31.
0015 %
0016 %   This function is compatible but the number of seconds is not limited to
0017 %   a 32-bit integer, any MATLAB double precision number may be used.  Also,
0018 %   fractional seconds are allowed.
0019 
0020 %   Author:      Peter J. Acklam
0021 %   Time-stamp:  2003-06-22 19:38:22 +0200
0022 %   E-mail:      pjacklam@online.no
0023 %   URL:         http://home.online.no/~pjacklam
0024 
0025    nargsin = nargin;
0026    error(nargchk(0, 6, nargsin));
0027    if nargsin
0028       argv = { 1 1 1 0 0 0 };
0029       argv(1:nargsin) = varargin;
0030    else
0031       argv = num2cell(clock);
0032    end
0033    [year, month, day, hour, minute, second] = deal(argv{:});
0034 
0035    secs = 86400 * (date2jd(year,month,day,hour,minute,second) - date2jd(1970, 1, 1));

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