UTC2POSIXTIME Convert serial date number in UTC to POSIX time. Syntax: S = UTC2POSIXTIME(D) Description: S = UTC2POSIXTIME(D) returns the POSIX times S corresponding to the serial date numbers in scalar, vector or array D, using the straight forward method (see note below). Notes: This function provides a compatibility interface for MATLAB and Octave, computing the conversion using a straight forward linear scaling: S = 86400 * (D - 719529) This is consistent with the POSIX specification (not counting leap seconds, using the same value for a leap second and its successor). Examples: % Compare the conversion of current time to the default shell current time. tz_offset = -1; s = utc2posixtime(now()+tz_offset/24) ! date +%s%N fprintf('%.0f\n',fix(1e+9*s)) See also: POSIXTIME POSIXTIME2UTC Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function s = utc2posixtime(d) 0002 %UTC2POSIXTIME Convert serial date number in UTC to POSIX time. 0003 % 0004 % Syntax: 0005 % S = UTC2POSIXTIME(D) 0006 % 0007 % Description: 0008 % S = UTC2POSIXTIME(D) returns the POSIX times S corresponding to the serial 0009 % date numbers in scalar, vector or array D, using the straight forward 0010 % method (see note below). 0011 % 0012 % Notes: 0013 % This function provides a compatibility interface for MATLAB and Octave, 0014 % computing the conversion using a straight forward linear scaling: 0015 % S = 86400 * (D - 719529) 0016 % This is consistent with the POSIX specification (not counting leap seconds, 0017 % using the same value for a leap second and its successor). 0018 % 0019 % Examples: 0020 % % Compare the conversion of current time to the default shell current time. 0021 % tz_offset = -1; 0022 % s = utc2posixtime(now()+tz_offset/24) 0023 % ! date +%s%N 0024 % fprintf('%.0f\n',fix(1e+9*s)) 0025 % 0026 % See also: 0027 % POSIXTIME 0028 % POSIXTIME2UTC 0029 % 0030 % Authors: 0031 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0032 0033 % Copyright (C) 2013-2016 0034 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears 0035 % <http://www.socib.es> 0036 % 0037 % This program is free software: you can redistribute it and/or modify 0038 % it under the terms of the GNU General Public License as published by 0039 % the Free Software Foundation, either version 3 of the License, or 0040 % (at your option) any later version. 0041 % 0042 % This program is distributed in the hope that it will be useful, 0043 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0044 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0045 % GNU General Public License for more details. 0046 % 0047 % You should have received a copy of the GNU General Public License 0048 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0049 0050 error(nargchk(1, 1, nargin, 'struct')); 0051 0052 s = 86400 * (d - 719529); 0053 0054 end