How to convert the following UTC to serial date number?

30 views (last 30 days)
I have a UTC data in the format YYYY-DOYThh:mm:ss.fffZ (Example-2018-345T02:19:02.175Z). What format can I use for it to convert it into serial date number using datenum? The main issue I am facing is with the format DOY as I wasn't able to find any suitable format for this in the datenum documentation. However, I can take care of the rest of them easily. Here I am attaching a sample code I used for this case. The first line is there as I am extracting UTC from a dataset.
utc_t=data(:,5);
match=["T","Z"];
utc=erase(utc_t,match);
format='yyyy-HH:MM:SS:FFF';%This is incomplete as I have not incorporated DOY format here
time=datenum(utc,format);

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jan 2022
format long g
utc_t = '2018-345T02:19:02.175Z'
utc_t = '2018-345T02:19:02.175Z'
utc_dt = datetime(utc_t, 'InputFormat', "uuuu-DDD'T'HH:mm:ss.SSS'Z'")
utc_dt = datetime
11-Dec-2018 02:19:02
time = datenum(utc_dt)
time =
737405.096552951
  2 Comments
Steven Lord
Steven Lord on 25 Jan 2022
Unless you absolutely need to work with the serial date numbers, I'd advise you to work with the datetime array utc_dt instead of the double array time. You should be able to do just about everything with datetime that you could do with the date numbers. If you find something you can do with datenums that you can't with datetime, please describe what you're trying to do.

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!