Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
UNIX Timestamps to matlab serial date

Subject: UNIX Timestamps to matlab serial date

From: Andrew Brampton

Date: 22 Apr, 2005 16:54:47

Message: 1 of 5

Hi,
I've got some log files I'm reading with matlab, and I want to convert unix
timestamps (in the logs) in to something Matlab can use. I see Matlab has
its own date format (serial date) and I was wondering if there was a way I
could convert to these.

Thanks
Andrew

Subject: UNIX Timestamps to matlab serial date

From: Steven Lord

Date: 22 Apr, 2005 12:04:09

Message: 2 of 5


"Andrew Brampton" <andrew@bramp.freeserve.co.uk> wrote in message
news:42691ec2$0$551$ed2619ec@ptn-nntp-reader03.plus.net...
> Hi,
> I've got some log files I'm reading with matlab, and I want to convert
> unix timestamps (in the logs) in to something Matlab can use. I see Matlab
> has its own date format (serial date) and I was wondering if there was a
> way I could convert to these.

Take a look at HELP DATENUM and HELP DATESTR to convert the timestamps
(which I assume are date strings) into serial date numbers and vice versa.

--
Steve Lord
slord@mathworks.com

Subject: UNIX Timestamps to matlab serial date

From: Andrew Brampton

Date: 22 Apr, 2005 17:14:10

Message: 3 of 5

I had looked at those functions, but a unix timestamp is not a "date
strings" its defined as the number of seconds since the unix epoch (ie
1/1/1970).

I thought since unix timestamps were a common that it be easy to convert,
but instead it seems a date string would be easier. I think I'm going to
have to script something outside of Matlab to convert my logs into something
readable, unless of course someone here knows how matlab can read unix time
stamps.

Thanks
Andrew

"Steven Lord" <slord@mathworks.com> wrote in message
news:d4b79p$sdt$1@fred.mathworks.com...
>
> "Andrew Brampton" <andrew@bramp.freeserve.co.uk> wrote in message
> news:42691ec2$0$551$ed2619ec@ptn-nntp-reader03.plus.net...
>> Hi,
>> I've got some log files I'm reading with matlab, and I want to convert
>> unix timestamps (in the logs) in to something Matlab can use. I see
>> Matlab has its own date format (serial date) and I was wondering if there
>> was a way I could convert to these.
>
> Take a look at HELP DATENUM and HELP DATESTR to convert the timestamps
> (which I assume are date strings) into serial date numbers and vice versa.
>
> --
> Steve Lord
> slord@mathworks.com
>

Subject: UNIX Timestamps to matlab serial date

From: Steve Simon

Date: 22 Apr, 2005 14:04:45

Message: 4 of 5

Andrew Brampton wrote:
> I had looked at those functions, but a unix timestamp is not a "date
> strings" its defined as the number of seconds since the unix epoch (ie
> 1/1/1970).
>
> I thought since unix timestamps were a common that it be easy to convert,
> but instead it seems a date string would be easier. I think I'm going to
> have to script something outside of Matlab to convert my logs into something
> readable, unless of course someone here knows how matlab can read unix time
> stamps.
>
> Thanks
> Andrew
>
> "Steven Lord" <slord@mathworks.com> wrote in message
> news:d4b79p$sdt$1@fred.mathworks.com...
>
>>"Andrew Brampton" <andrew@bramp.freeserve.co.uk> wrote in message
>>news:42691ec2$0$551$ed2619ec@ptn-nntp-reader03.plus.net...
>>
>>>Hi,
>>>I've got some log files I'm reading with matlab, and I want to convert
>>>unix timestamps (in the logs) in to something Matlab can use. I see
>>>Matlab has its own date format (serial date) and I was wondering if there
>>>was a way I could convert to these.
>>
>>Take a look at HELP DATENUM and HELP DATESTR to convert the timestamps
>>(which I assume are date strings) into serial date numbers and vice versa.
>>
>>--
>>Steve Lord
>>slord@mathworks.com
>>
>
>
>

If you read the timestamp in as a string value, you would need to get
the equivalent serial date number for January 1, 1970, and add the
timestamp value (converted to a number and divided by the number of
seconds per day) to get the serial date number for the timestamp:

% offset (serial date number for 1/1/1970)
dnOffset = datenum('01-Jan-1970');

% assuming it's read in as a string originally
tstamp = '1114178400';

% convert to a number, dived by number of seconds
% per day, and add offset
dnNow = str2num(tstamp)/(24*60*60) + dnOffset;

% date string
datestr(dnNow)

Subject: UNIX Timestamps to matlab serial date

From: Anders Björk

Date: 22 Apr, 2005 23:32:38

Message: 5 of 5

On Peter Jacklams site he put some time-utils
http://home.online.no/~pjacklam/matlab/software/util/timeutil/index.html

PJ was one of the major contributors here one-two years ago.
BR
Anders
"Andrew Brampton" <andrew@bramp.freeserve.co.uk> skrev i meddelandet
news:42692350$0$567$ed2619ec@ptn-nntp-reader03.plus.net...
>I had looked at those functions, but a unix timestamp is not a "date
>strings" its defined as the number of seconds since the unix epoch (ie
>1/1/1970).
>
> I thought since unix timestamps were a common that it be easy to convert,
> but instead it seems a date string would be easier. I think I'm going to
> have to script something outside of Matlab to convert my logs into
> something readable, unless of course someone here knows how matlab can
> read unix time stamps.
>
> Thanks
> Andrew
>
> "Steven Lord" <slord@mathworks.com> wrote in message
> news:d4b79p$sdt$1@fred.mathworks.com...
>>
>> "Andrew Brampton" <andrew@bramp.freeserve.co.uk> wrote in message
>> news:42691ec2$0$551$ed2619ec@ptn-nntp-reader03.plus.net...
>>> Hi,
>>> I've got some log files I'm reading with matlab, and I want to convert
>>> unix timestamps (in the logs) in to something Matlab can use. I see
>>> Matlab has its own date format (serial date) and I was wondering if
>>> there was a way I could convert to these.
>>
>> Take a look at HELP DATENUM and HELP DATESTR to convert the timestamps
>> (which I assume are date strings) into serial date numbers and vice
>> versa.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>>
>
>

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us