-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnixSecs2Date.m
More file actions
31 lines (29 loc) · 1.35 KB
/
UnixSecs2Date.m
File metadata and controls
31 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [year, month, day, hour, minute, second] = UnixSecs2Date(secs)
%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.
% Author: Peter J. Acklam
% Time-stamp: 2003-01-14 21:32:11 +0100
% E-mail: pjacklam@online.no
% URL: http://home.online.no/~pjacklam
error(nargchk(1, 1, nargin));
format long
[year, month, day, hour, minute, second]= jd2date(double(secs) / 86400 + date2jd(1970, 1, 1));
format short