Extracting first 10 digits (or numbers) from 16 digit number?

Hi,
I am trying to convert epoch time to local time. Epoch time is given in 13 digits while to correctly convert epoch time into local time, 10 digits are required. For instance, the timestamp vector has values like [1566245599500; 1566245595600; 1566245601700; 1566245598800 ...] and i want 10 digits from each row and store in a new column, say datetime = [1566245599; 1566245595; 15662455601; 1566245598].
My questions are: (i) how to select first 10 digits of 13-digit no? (ii) how to do it for all rows in a column vector without running a loop? I am avoiding running a loop because I am working on multiple excel sheets, which will increase processing time.
Help would be highly appreciated!

 Accepted Answer

a = [1566245599500; 1566245595600; 1566245601700; 1566245598800]%read the array;
a = 4×1
1.0e+12 * 1.5662 1.5662 1.5662 1.5662
b = floor(a./1000) %exclude last 3 digits
b = 4×1
1.0e+09 * 1.5662 1.5662 1.5662 1.5662

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!