How to change time stamp to readable date and time without giving reference time ?

3 views (last 30 days)
Below code is to generate Date and Time from a timeStamp but with the help of reference date and time (refTime). However , I need to generate date and time without giving reference time. How can i do that? Thanks in advance.
refTime = [2016,08,02,10,28,52];
refNum = datenum(refTime);
% refStr = datestr(refNum,'yyyy-mm-dd HH:MM:SS.FFF');
Dat_timeStamp = [1.454958517009081e+18,1.454958517014576e+18, 1.454958517018680e+18];
% Processing data
% dn = 24*60*60*1000*1000; % Microseconds! I have changed this equation to many options but nothing was helpful
for i = 1 : size(Dat_timeStamp,2)-1
usecs = double(Dat_timeStamp(1,i+1)) - double(Dat_timeStamp(1,1));
secsDiff = usecs / 1e9;
matDateTime = refNum + secsDiff / (24*60*60);
gzStr{i,1} = datestr(matDateTime,'yyyy-mm-dd HH:MM:SS'); % I can't use 'SS.FFFFFF'
end;
  3 Comments
Naveed Khan
Naveed Khan on 29 Feb 2016
hank you for your answer, Its almost what i want, but my timestamp is in 19 digits. i.e. in nanoseconds, so should i also divide it by 1000, or by 1000000000"

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Feb 2016
  9 Comments
Naveed Khan
Naveed Khan on 2 Mar 2016
Thanks Walter Roberson for your guidance and help. Finally i get the required output. once again thanks .....:)

Sign in to comment.

More Answers (1)

Peter Perkins
Peter Perkins on 7 Mar 2016
When I do this
>> datetime('08-Feb-2016 10:28:52','Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS') - seconds(1.454956105656222e+9)
ans =
31-Dec-1969 16:00:26.343777832
It makes me suspect that the issue is not only time zones, not only floating point round-off, but also leap seconds.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!