仅在MATLAB中将日期/时间转换为序号
我正在使用仅在MATLAB中将日期/时间转换为序号,matlab,date,time,julian-date,Matlab,Date,Time,Julian Date,我正在使用 c=时钟 在MATLAB中获取当前日期和时间。我想转换当前日期,以便可以将一年中的天数提取为整数,并将其存储为单个向量值。即第1天到第365天 我搜索了一个Julian Day函数,但函数jd=juliandate()至少需要3个元素,并使用年份和时间对其进行格式化。我似乎找不到这样的函数。如何将日期转换为整数 i、 e Feb 1st=32作为整数 注意:我仍然想将时钟中的时间存储在一个单独的向量中,作为hh:ss减去截至同年1月1日的天数如何 >> x = clock
c=时钟代码>
在MATLAB中获取当前日期和时间。我想转换当前日期,以便可以将一年中的天数提取为整数,并将其存储为单个向量值。即第1天到第365天
我搜索了一个Julian Day函数,但函数jd=juliandate()
至少需要3个元素,并使用年份和时间对其进行格式化。我似乎找不到这样的函数。如何将日期转换为整数
i、 e Feb 1st=32作为整数
注意:我仍然想将时钟中的时间存储在一个单独的向量中,作为hh:ss减去截至同年1月1日的天数如何
>> x = clock
>> y = zeros(1,6);
>> y(1) = x(1);
>> y(2:3) = [1 1]
>> mjuliandate(x) - mjuliandate(y)
编辑:如果没有忽略小时、分钟或秒,那么使用mjuliandate
比juliandate
更好,因为它从午夜开始计算,而不是从中午开始计算。减去截至同年1月1日的天数如何
>> x = clock
>> y = zeros(1,6);
>> y(1) = x(1);
>> y(2:3) = [1 1]
>> mjuliandate(x) - mjuliandate(y)
编辑:如果没有忽略小时、分钟或秒,那么使用mjuliandate
比juliandate
更好,因为它从午夜开始计算,而不是从中午开始计算。减去截至同年1月1日的天数如何
>> x = clock
>> y = zeros(1,6);
>> y(1) = x(1);
>> y(2:3) = [1 1]
>> mjuliandate(x) - mjuliandate(y)
编辑:如果没有忽略小时、分钟或秒,那么使用mjuliandate
比juliandate
更好,因为它从午夜开始计算,而不是从中午开始计算。减去截至同年1月1日的天数如何
>> x = clock
>> y = zeros(1,6);
>> y(1) = x(1);
>> y(2:3) = [1 1]
>> mjuliandate(x) - mjuliandate(y)
编辑:如果未忽略小时、分钟或秒,则使用mjuliandate
优于juliandate
,因为它从午夜开始计数,而不是从中午开始。您可以使用转换为datenum
:
c = clock();
tsNow = datenum(c);
tsStart = datenum([c(1) 1 1 0 0 0]); % timestamp at the beginning of this year
daysInYear = tsNow - tsStart;
datenums正是您想要的,即自给定的固定时间戳(1-Jan-0000)起的天数。因此,这种差异产生了一年中的天数——包括闰年等。
如果您需要完整天数,请使用下限(daysInYear)
。您可以使用转换为日期数
:
c = clock();
tsNow = datenum(c);
tsStart = datenum([c(1) 1 1 0 0 0]); % timestamp at the beginning of this year
daysInYear = tsNow - tsStart;
datenums正是您想要的,即自给定的固定时间戳(1-Jan-0000)起的天数。因此,这种差异产生了一年中的天数——包括闰年等。
如果您需要完整天数,请使用下限(daysInYear)
。您可以使用转换为日期数
:
c = clock();
tsNow = datenum(c);
tsStart = datenum([c(1) 1 1 0 0 0]); % timestamp at the beginning of this year
daysInYear = tsNow - tsStart;
datenums正是您想要的,即自给定的固定时间戳(1-Jan-0000)起的天数。因此,这种差异产生了一年中的天数——包括闰年等。
如果您需要完整天数,请使用下限(daysInYear)
。您可以使用转换为日期数
:
c = clock();
tsNow = datenum(c);
tsStart = datenum([c(1) 1 1 0 0 0]); % timestamp at the beginning of this year
daysInYear = tsNow - tsStart;
datenums正是您想要的,即自给定的固定时间戳(1-Jan-0000)起的天数。因此,这种差异产生了一年中的天数——包括闰年等。
如果需要完整天数,请使用floor(daysInYear)