Unix Timestamp & Epoch Conversion in Matlab
Matlab (matrix laboratory) is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. It allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. It also provides many date time functions to handle date time functionality.
Here we will explain Matlab date time functions to get current epoch or Unix timestamp, convert timestamp to date and convert date to epoch or Unix timestamp.
Get current epoch or Unix timestamp in MatlabYou can get the current unix timestamp using following.
int32(floor(60*60*24 * (datenum(now) - datenum('01-Jan-1970')))) * 1000
Convert epoch or Unix timestamp to date in Matlab
You can convert unix timestamp to human readable date using following.
unixTimestamp = 1624705077;
date = datestr(unixTimestamp/86400 + datenum(1970,1,1));
Convert date to epoch or unix timestamp in Matlab
You can unix timestamp from human readable date using following.
int32(floor(86400 * (datenum('04-June-2021') - datenum('01-Jan-1970'))))
More about date time in Matlab
Also, read:
- Unix Timestamp & Epoch Conversion in PHP
- Unix Timestamp & Epoch Conversion in Java
- Unix Timestamp & Epoch Conversion in JavaScript
- Unix Timestamp & Epoch Conversion in Perl
- Unix Timestamp & Epoch Conversion in Python
- Unix Timestamp & Epoch Conversion in TypeScript
- Unix Timestamp & Epoch Conversion in MySQL
- Unix Timestamp & Epoch Conversion SQL Server
- Unix Timestamp & Epoch Conversion in C# (C-Sharp)
- Unix Timestamp & Epoch Conversion in Kotlin
- Unix Timestamp & Epoch Conversion in Go
- Unix Timestamp & Epoch Conversion in Ruby
- Unix Timestamp & Epoch Conversion in VBA
- Unix Timestamp & Epoch Conversion in Rust