• matlab timestamp转换


    问题 如何将matlab时间戳进行加减

    matlab的sac文件时间读取后,需要加上八小时才是本地时间。

    用rdsac.m读取后的时间t已经是matlab时间戳的样式,如下

    t(1:3)

    ans =

    737005.94868136
    737005.948692934
    737005.948704508

    :

    T是一列生成的时间序列,

    t0=datenum(2017,11,06,00,00,00);
    dt=1/(24*60*60);
    tf=datenum(2017,11,09,23,59,59);
    T=t0:dt:tf; T=T';

    T(1:3)

    ans =

    737005
    737005.000011574
    737005.000023148

    解决

    usecs = double(T(2)) - double(T(1));%看时间间隔

    secsDiff = usecs / 1e6;
    tt=t+secsDiff*86400*8; %加上8小时变为本地时间 86400*8*(T(2)-T(1))

     

    usecs = double(t(2)) - double(t(1));
    % secsDiff = usecs / 1e6;
    secsDiff = usecs;
    tt=t+secsDiff*3600*8;%加上8小时变为本地时间 3600*8*(T(3)-T(2))

    运行结果================

    datestr(tt(1:5))

    ans =

    5×20 char array

    '06-Nov-2017 22:46:06'
    '06-Nov-2017 22:46:07'
    '06-Nov-2017 22:46:08'
    '06-Nov-2017 22:46:09'
    '06-Nov-2017 22:46:10'

    datestr(T(81967:81967+5))

    ans =

    6×20 char array

    '06-Nov-2017 22:46:06'
    '06-Nov-2017 22:46:07'
    '06-Nov-2017 22:46:08'
    '06-Nov-2017 22:46:09'
    '06-Nov-2017 22:46:10'

    参考

    https://stackoverflow.com/questions/10103670/matlab-converting-timestamps-to-readable-format-given-the-reference-date-time

  • 相关阅读:
    java积累
    mybatis
    Netty
    springcloud相关笔记整理
    java基础总结笔记
    读书笔记-RocketMQ实战与原理解析
    读书笔记-kafka权威指南
    读书笔记-rabbitmq实战指南
    Centos 部署ServiceDesk
    IDEA将新建项目上传至GitLab
  • 原文地址:https://www.cnblogs.com/gisalameda/p/8057388.html
Copyright © 2020-2023  润新知