主要内容

DateTime Clock

R2026b

Output current simulation calendar date and time as DateTime data type

Since R2026b

  • DateTime Clock block icon

Libraries:
Simulink / DateTime

Description

The DateTime Clock block outputs the current simulation calendar date and time as DateTime data type. Specify characteristics such as time point, storage data type, and time standard.

Use these other DateTime blocks to interact with the DateTime Clock block.

DescriptionBlock

Convert time points, storage data types, or time points and storage data types, of DateTime signal.

DateTime Data Type Converter

Convert between DateTime time standards.

DateTime Time Standard Converter

Convert DateTime to calendar time format.

DateTime to Calendar Time

Output DateTime from a time point.

To DateTime

Extract value of DateTime input signal.

From DateTime

Convert DateTime signal data type to formatted string.

DateTime to Formatted String

Time Standards

Collectively, the DateTime blocks support these time standards:

  • International Atomic Time (TAI) — Atomic time based on the International System of Units (SI) second computed and reported by scientific laboratories. TAI has no leap seconds.

  • Coordinated Universal Time (UTC) — Atomic time computed by subtracting a particular number of leap seconds from TAI. Leap seconds keep UTC as close to Universal Time as possible while still ticking at the rate specified by TAI.

  • Terrestrial Time (TT) — Time standard that astronomers use to tag measurements taken at the Earth surface. TT is 32.184 seconds ahead of TAI.

Examples

expand all

This example shows how the calendar representation of a DateTime signal corresponds to its stored value for each value of the Time point parameter.

For more information on the allowed values of the Time point parameter, see the DateTime Clock block documentation.

Both DateTime Clock blocks in "Area A" of model ex_datetime_clock_block_time_points are set to 12:00 AM UTC, January 1, 1970 at simulation time 0. This is the UNIX epoch, the time at which DateTime Clock blocks with Time point set to Seconds since Unix epoch output a stored value of 0. This value is interpreted differently depending on whether the DateTime Clock block's Time standard is set to TAI or UTC. The UTC clock block reads 01-Jan-1970 00:00:00, while the TAI clock block accounts for a 10-second offset between TAI and UTC at the inception of UTC and reads 01-Jan-1970 00:00:10.

All DateTime Clock blocks in "Area B" of model ex_datetime_clock_block_time_points are set to 12:00 PM UTC, January 1, 2000 at simulation time 0. The TAI clock readings are exactly 32 seconds ahead of the UTC clocks. The TT clock readings are 64.184 seconds ahead of the UTC clocks, which is truncated to 64 seconds by the Display block.

Time points can be split into two categories:

  • DateTime signals with Time point set to Seconds since Unix epoch, Seconds since NTP epoch, or Seconds since TAI epoch report elapsed time since a universal real-world instant.

    • Example: DateTime Clock2, DateTime Clock3, and DateTimeClock4 all report the elapsed time since the UNIX epoch. However, DateTime Clock3 and DateTime Clock4 output a stored value that is 22 seconds greater than the output of DateTime Clock2 because the TAI and TT clocks count the 22 leap seconds that elapsed between 1970 and 2000. The TAI and TT clock readings include additional 10-second and 32.184-second offsets, respectively, which are accounted for by blocks that interpret DateTime signals. DateTime Clock3 and DateTime Clock4 differ from DateTime Clock2 both in their clock readings and in how many seconds they count since the UNIX epoch, but they agree about the universal real-world instant corresponding to a stored value of 0 (the UNIX epoch; see Area A).

  • DateTime signals with Time point set to Julian date, Modified Julian date, or J2000.0 date report elapsed time since a particular day and time of day on their own time standard.

    • Example: DateTime Clock8 outputs a stored value of 0.00037037.... This value includes offsets for both the 22 elapsed leap seconds and the 10-second difference between TAI and UTC at the inception of UTC. This is because the time corresponding to a stored value of 0 for DateTime Clock8 is 01-Jan-2000 12:00:00 TAI. The clock is set to 01-Jan-2000 12:00:00 UTC, 32 seconds later, and records an elapsed time since the epoch of 32/86400 = 0.00037037... days.

Block

Time point

Time standard

Clock reading at 01-Jan-2000 12:00:00 UTC

Stored value at 01-Jan-2000 12:00:00 UTC

Explanation of stored value

DateTime Clock2

Seconds since Unix epoch

UTC

01-Jan-2000 12:00:00

946728000

86400 seconds per day × 10957.5 days elapsed between 12:00 AM on 01-Jan-1970 and 12:00 PM on 01-Jan-2000.

DateTime Clock3

Seconds since Unix epoch

TAI

01-Jan-2000 12:00:32

946728022

94672800086400 seconds per day×10957.5 days elapsed between12:00 AM on 01-Jan-1970 and 12:00 PM on 01-Jan-2000+22leap seconds counted by TAI but not UTC946728022

The stored value is 22 seconds greater than DateTime Clock2 because 22 leap seconds have elapsed, but the clock reading is 32 seconds later than DateTime Clock2 because of the initial TAI-UTC offset.

DateTime Clock4

Seconds since Unix epoch

TT

01-Jan-2000 12:01:04

946728022

94672800086400 seconds per day×10957.5 days elapsed between12:00 AM on 01-Jan-1970 and 12:00 PM on 01-Jan-2000+22leap seconds counted by TT but not UTC946728022

The stored value is 22 seconds greater than DateTime Clock2 because 22 leap seconds have elapsed, but the clock reading is 64 seconds later than DateTime Clock2 because of the initial TT-UTC offset.

DateTime Clock5

Seconds since TAI epoch

TAI

01-Jan-2000 12:00:32

1325419232

132541920086400 seconds per day×15340.5 days elapsed between12:00 AM on 01-Jan-1958 and 12:00 PM on 01-Jan-2000+10seconds between TAI and UTC on 01-Jan-1972+22leap seconds counted by TAI but not UTC1325419232

DateTime Clock6

Julian date

UTC

01-Jan-2000 12:00:00

2451545

2451545 days elapsed between 12:00 PM on 24-Nov-4714 BC and 12:00 PM on 01-Jan-2000.

DateTime Clock7

Modified Julian date

TT

01-Jan-2000 12:01:04

51544.50074287

51544.50000000...days elapsed between 12:00 AM on 17-Nov-1858 and 12:00 PM on 01-Jan-2000+0.00048824...1/86400 days per second×42.184 seconds between TT and UTC on 01-Jan-1972+0.00025463...1/86400 days per second×22 leap seconds counted by TT but not UTC51544.50074287...

DateTime Clock8

J2000.0 date

TAI

01-Jan-2000 12:00:32

0.00037037037037037

0.00000000...days elapsed at 12:00 PM on 01-Jan-2000+0.00011574...1/86400 days per second×10 seconds between TAI and UTC on 01-Jan-1972+0.00025463...1/86400 days per second×22 leap seconds counted by TAI but not UTC0.00037037...

model='ex_datetime_clock_block_time_points';
load_system(model)
sim(model);
open_system(model)

This example shows the behavior of three DateTime Clock blocks with Time standard set to UTC. Each block steps through the leap second that occurred on December 31, 2016.

The first block's Account for new leap seconds after simulation start parameter is cleared. This block ignores the leap second and immediately rolls over to January 1, 2017 (Display block).

The second block's Account for new leap seconds after simulation start parameter is selected and its Output DateTime as bus with leap second indicator parameter is cleared. During the leap second, this block repeats the preceding 23:59:59 second (Display1 block).

The third block's Account for new leap seconds after simulation start and Output DateTime as bus with leap second indicator parameters are both selected. This block outputs a two-element virtual bus whose first element is a DateTime signal and whose second element is a boolean signal. Use a Bus Selector block to separate the virtual bus into its constituent signals. During a leap second, the DateTime signal repeats the preceding 23:59:59 timestamp (Display3 block) and the boolean signal is true (Display4 block). The DateTime to Formatted String block accepts the virtual bus as input and treats it as a DateTime signal with a 23:59:60 timestamp (Display2 block).

model='ex_datetime_clock_block_leap_seconds';
load_system(model)
sim(model);
open_system(model)

Ports

Output

expand all

Simulation calendar date and time, returned as a scalar DateTime signal.

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Main

Initial date and time source, specified as Inherit from model or Specify value.

Dependencies

To set the Date and time at simulation time zero parameter, select Specify value.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: InitialDateTimeSource
Values: Inherit from model (default) | Specify value

Date and time at simulation time zero, specified as a scalar datetime object.

This parameter must resolve to a date between January 1, 1400 and December 31, 9999.

Tip

  • The datetime object must be either unzoned or have the same correct time standard as the DateTime Clock block.

  • If the DateTime Clock block Initial date and time source is set to Specify value, the DateTime Clock block Date and time at simulation time zero parameter value takes precedence over the Date and time at simulation time zero model configuration parameter.

Dependencies

To set the date and time at simulation time zero, select Specify value.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: DateTimeAtSimulationTimeZero
Values: datetime(2000,1,1,0,0,0) (default) | scalar datetime object

Specify the diagnostic for when clock rolls over its storage data type maximum value as None, Warning, or Error.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: DiagnosticForClockRollOver
Values: None (default) | Warning | Error

Specify the time interval between samples.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: SampleTime
Values: 0 (default) | scalar | vector

Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.

Programmatic Use

Parameter: ZeroCross
Type: character vector, string
Values: 'on' | 'off'
Default: 'on'

Signal Attributes

Specify the current clock time point as Seconds since Unix epoch, Seconds since NTP epoch, Seconds since TAI epoch, Julian date, Modified Julian date, or J2000.0 date. The DateTime Clock block uses this value to determine the clock epoch.

The Seconds since Unix epoch, Seconds since NTP epoch, and Seconds since TAI epoch options describe time elapsed since a universal instant in time. The Julian date, Modified Julian date, and J2000.0 date options are the number of days elapsed since their respective epochs.

This table lists the epoch corresponding to each possible value for the Time point parameter. The epoch for the currently selected Time point is displayed on the dialog box.

Time PointEpoch

Seconds since Unix epoch

1970-01-01T00:00:00 UTC

Seconds since NTP epoch

1900-01-01T00:00:00 UTC

Seconds since TAI epoch

1958-01-01T00:00:00 TAI

Julian date

4714 BC-11-24T12:00:00

Modified Julian date

1858-11-17T00:00:00

J2000.0 date

2000-01-01T12:00:00

For more information on storage type constraints, see Simulink.DateTimeType.

Dependencies

To change the current clock epoch, select a different Time point value.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: TimePoint
Values: Seconds since Unix epoch (default) | Seconds since NTP epoch | Seconds since TAI epoch | Julian date | Modified Julian date | J2000.0 date

Select the DateTime storage data type:

  • double

  • int32

  • uint32

  • fixdt(0,64,32)

  • fixdt(1,64,32)

  • fixdt(0,128,64)

  • fixdt(1,128,64)

For more information on storage type constraints, see Simulink.DateTimeType.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: StorageDataType
Values: double (default) | int32 | uint32 | fixdt(0,64,32) | fixdt(1,64,32) | fixdt(0,128,64) | fixdt(1,128,64)

Specify the current clock time standard:

  • TAI — International Atomic Time

  • UTC — Coordinated Universal Time

  • TT — Terrestrial Time

For more information on storage type constraints, see Simulink.DateTimeType.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: TimeStandard
Values: TAI (default) | UTC | TT

Option to account for new leap seconds after model simulation starts.

If Account for new leap seconds after simulation start is selected, the DateTime Clock block inserts an extra second at the end of days that experienced a positive leap second. For more information, see the Output DateTime as bus with leap second indicator parameter.

Dependencies

To enable this parameter, set the Time standard parameter to UTC.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: AccountForLeapSeconds
Values: "off" (default) | "on"

Option to output leap second indicator as a virtual bus or a signal. The block behavior is:

  • If the Output DateTime as bus with leap second indicator parameter is selected, the DateTime Clock block outputs a two-element virtual bus. The first element is a DateTime signal and the second element is a Boolean signal.

    During a leap second, the DateTime signal repeats the preceding 23:59:59 timestamp and the Boolean signal is true. Otherwise, the Boolean signal is false. DateTime blocks can accept this virtual bus as input. DateTime blocks that receive a virtual bus of a 23:59:59 timestamp and a Boolean signal with value true treat the bus as a DateTime signal with a 23:59:60 timestamp.

  • If Output DateTime as bus with leap second indicator is cleared, the DateTime Clock block outputs a DateTime signal. During a leap second, the signal repeats the preceding 23:59:59 timestamp.

Dependencies

To enable this parameter:

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: OutputLeapSecondIndicator
Values: "on" (default) | "off"

Block Characteristics

Data Types

Boolean | bus | datetime

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

yes

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2026b