필터 지우기
필터 지우기

Time Stamp is a Large Number

조회 수: 3 (최근 30일)
Cameron Power
Cameron Power 2018년 6월 20일
답변: Peter Perkins 2018년 7월 5일
I am trying to break apart this file I have but the time column has a large number as the time (this is because the time is in 5 minute intervals). As an example 201601010000 (shown in Matlab as 2.0160101000e+11) represents January 1, 2016, 12:00AM or 00:00Hr (24 Hr time). Any help is welcome, thank you.
  댓글 수: 2
Stephen23
Stephen23 2018년 6월 20일
@Cameron Power: Please upload a sample file by clicking the paperclip button. Several file importing functions correctly import dates without requiring them to be converted to/from a large number, and they are the recommended way to handle dates.
Cameron Power
Cameron Power 2018년 6월 20일
Here is a csv sample

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 6월 20일
편집: Stephen23 2018년 6월 20일
Use either readtable or textscan and set the format to specify the date, something like this:
N = number of columns
fmt = repmat('%f',1,N-1);
fmt = ['%{yyyyMMddHHmmss}D',fmt];
Both readtable and textscan contain a useful example under the heading "Read Foreign-Language Dates", you should try those examples and adapt them to your situation.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 7월 5일
If you have text, Stephen's advice is good. If you have a number, you can split it into two pieces and use datetime to do at least part of the work:
>> x = 201601010000
x =
201601010000
>> xdate = floor(x/10000)
xdate =
20160101
>> xtime = x - 10000*xdate
xtime =
0
>> datetime(xdate,'ConvertFrom','yyyymmdd')
ans =
datetime
01-Jan-2016 00:00:00

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by