%% Convert Datetime Array to Julian Dates
% Create datetime values and convert them to the equivalent Julian dates. Show the differences in Julian dates between zoned and unzoned datetime values. The best practice is to specify a time zone for a datetime array before calling juliandate.
% Create a datetime array and specify its time zone.

t1 = datetime('2016-07-29 10:05:24') + calmonths(1:3);
t1.TimeZone = 'America/New_York'

%
% Convert t1 to the equivalent Julian dates. juliandate accounts for the time zone offset when it computes Julian dates.

format longG
jd1 = juliandate(t1)

%
% Create a datetime array with the same values as t1, but with no time zone. Convert it to the equivalent Julian dates. juliandate treats the times in t2 as UTC times, with no time zone offset.

t2 = datetime('2016-07-29 10:05:24') + calmonths(1:3);
jd2 = juliandate(t2)

%
% Show the differences between jd2 and jd1. The differences are equal to the time offset, in days, between UTC and the time zone of jd1.

jd2 - jd1

% Copyright 2012 The MathWorks, Inc.