Matlab时间
程序员文章站
2022-03-09 23:39:45
...
自带函数
startDate = datestr('1900-01-01 00:00:00', 'yyyy-mm-dd HH:MM:SS');
datestr(datenum(startDate) + 61710480/60/24, 'yyyymmdd')
datestr(now, 'yyyymmdd')
自定义函数
function flag = isLeapYear( year )
if (mod(year,4)==0&&mod(year,100)~=0) || mod(year,400)==0
flag=1;
else
flag=0;
end
%month(datetime(year, 1, doy))
%day(datetime(year, 1, doy))
function [month,day] = doy2md(doy,year)
dom=[31,28,31,30,31,30,31,31,30,31,30,31];
if isLeapYear(year)
dom(2)=29;
end
day=doy;
month=1;
while(day>dom(month))
day=day-dom(month);
month=month+1;
end
tic, toc
number = 10000;
last_t = 0;
tic;
for i=1:number
pause(0.1);
t=toc;
if t-last_t>=1
last_t = t;
hh = floor(t/3600);
mm = floor(t/60) - 60*hh;
ss = t - 60*mm - 3600*hh;
use_time = sprintf("%02d:%02d:%02.3f", hh, mm, ss)
t = (t/i)*(number-i);
hh = floor(t/3600);
mm = floor(t/60) - 60*hh;
ss = t - 60*mm - 3600*hh;
left_time = sprintf("%02d:%02d:%02.3f", hh, mm, ss)
clc;
fprintf('已用时%s,剩余时间%s\n', use_time, left_time );
end
end
进度条
number = 10000;
for i=1:number
progress = floor(i/number*30);
fprintf(['进度:', repmat('█', 1, progress), repmat('□', 1, 30-progress), ' %2.2f%%\n'], i/number*100);
pause(0.1);
end
时间
julian day得到日期
julian_day = 25854.1424; %(days since 1950-01-01 00:00:00 UTC)
date_obj = datetime(juliandate(1950, 1, 1, 0, 0, 0) + julidan_day, ...
'ConvertFrom', 'juliandate', ...
'TimeZone', 'UTC', 'Format', 'yyyy-MM-dd HH:mm:ss.SSS Z');
上一篇: python怎么去掉数据的方括号