getUTC

Version 2.2.0.0 (38.5 KB) by Rik
get the current time in UTC
91 Downloads
Updated 21 Nov 2023

getUTC documentation

View ifversion on File Exchange Open in MATLAB Online

Table of contents

Description

For some applications it is necessary to know the current UTC time. This function has three methods to determine the UTC timestamp: an implementation written in C (which will be compiled), a call to a website, and a system call.

There are several methods implemented in this function:

  • An implementation that requires a C mex function (which will be compiled).
    This method requires write access to a folder and a working C compiler. The compilation result will be stored to a subdirectory of a folder similar to the AddOn path, or the tempdir, or the current folder. Write permission is tested in that order.
  • An implementation using https://www.utctime.net/utc-timestamp.
    The NIST has a server that returns the time, but it currently blocks API access, hence this replacement.
    This method requires internet access.
  • The local time and timezone offset can be determined with the wmic command or the get-date Powershell function (Windows) or the date command (Linux and Mac).
    On Windows an NTP query is also implemented (internet connectivity is checked prior to this call).

To speed up the usage of this method, you can cache the difference with now() in a persistent variable, that way you avoid the need for a slow system call.

Matlab/Octave

Syntax

atomTime = getUTC

Output arguments

Argument Description
atomTime The current UTC in the numeric format produced by datenum. Depending on which method is used, the accuracy may be reduced by longer execution times (up to a second).

Compatibility, version info, and licence

Compatibility considerations:

  • Some older releases don't support the web implementation.
  • The normal system call hangs on ML7.1 on XP. Since ML6.5 works fine on Windows 10, it seems reasonable to assume that the OS is the cause of the hang. For XP (and older) there is an alternative strategy in place, but this has a higher likelihood to fail.
  • Similarly, as wmic has been deprecated, a Powershell alternative should be used on newer versions of Windows. The need for this is automatically detected.
Test suite result Windows Linux MacOS
Matlab R2023b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2023a W11 : Pass ubuntu_22.04 : Pass
Matlab R2022b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2022a W11 : Pass
Matlab R2021b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2021a W11 : Pass
Matlab R2020b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2020a W11 : Pass
Matlab R2019b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2019a W11 : Partial
Matlab R2018a W11 : Partial ubuntu_22.04 : Partial
Matlab R2017b W11 : Partial ubuntu_22.04 : Partial Monterey : Partial
Matlab R2016b W11 : Partial ubuntu_22.04 : Partial Monterey : Partial
Matlab R2015a W11 : Pass ubuntu_22.04 : Pass
Matlab R2013b W11 : Partial
Matlab R2007b W11 : Partial
Matlab 6.5 (R13) W11 : Partial
Octave 8.2.0 W11 : Pass
Octave 7.2.0 W11 : Pass
Octave 6.2.0 W11 : Pass ubuntu_22.04 : Catalina :
Octave 5.2.0 W11 : Pass
Octave 4.4.1 W11 : Pass Catalina :
Version: 2.2.0
Date:    2023-11-21
Author:  H.J. Wisselink
Licence: CC by-nc-sa 4.0 ( https://creativecommons.org/licenses/by-nc-sa/4.0 )
Email = 'h_j_wisselink*alumnus_utwente_nl';
Real_email = regexprep(Email,{'*','_'},{'@','.'})

Test suite

The tester is included so you can test if your own modifications would introduce any bugs. These tests form the basis for the compatibility table above. Note that functions may be different between the tester version and the normal function. Make sure to apply any modifications to both.

Cite As

Rik (2024). getUTC (https://github.com/thrynae/getUTC/releases/tag/v2.2.0), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2023b
Compatible with R13SP1 and later releases
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
2.2.0.0

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/v2.2.0

2.1.0

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/v2.1.0

2.0.1

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/v2.0.1

2.0.0

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/v2.0.0

1.1.0

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/v1.1.0

1.0.2

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/v1.0.2

1.0.1

See release notes for this release on GitHub: https://github.com/thrynae/getUTC/releases/tag/1.0.1

1.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.