Current date and time as serial date number
now function returns a serial date number that represents
the current time. However, it is recommended that you use
datetime values to represent points in time. To return the current time as
datetime value, use the
t = now returns the current date and time as a serial date
number. A serial date number represents the whole and fractional number of days starting
from a fixed, preset date (January 0,
Change the output display for numbers to long, fixed-decimal format. Then return the current date and time as a serial date number.
format longG t = now
t = 738210.637548958
The whole part of
t corresponds to the date, and the fractional part corresponds to the time of day. One way to show the date and time is to convert
t using the
d = datetime(t,'ConvertFrom','datenum')
d = datetime 23-Feb-2021 15:18:04
To represent the date alone, without the time of day, use the
floor function. Convert the result to a
datetime value for display.
t2 = floor(t)
t2 = 738210
d2 = datetime(t2,'ConvertFrom','datenum')
d2 = datetime 23-Feb-2021
MATLAB® Online™ returns the current date and time in Coordinated Universal Time (UTC) rather than local time.
To represent the current date and time as a serial date number, as text, or as a
datetime value, use the function calls shown in the table.
Current date as a serial date number
Current time as a serial date number
Current date and time as text
Current date and time as a