For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > UNIX Timestamps to matlab serial date









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author UNIX Timestamps to matlab serial date
Andrew Brampton

2005-04-22, 4:04 pm

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


Steven Lord

2005-04-22, 4:04 pm


"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


Andrew Brampton

2005-04-22, 4:04 pm

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...
>
> 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
>



Steve Simon

2005-04-22, 4:04 pm

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...
>
>
>
>


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)




Anders Björk

2005-04-22, 9:00 pm

On Peter Jacklams site he put some time-utils
http://home.online.no/~pjacklam/mat...util/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...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com