4.0

4.0 | 5 ratings Rate this file 44 Downloads (last 30 days) File Size: 6.36 KB File ID: #7244

Get UTC Time, Convert a UTC time to Datenum (supports vectors, Win/Linux)

by Abraham Cohn

 

23 Mar 2005 (Updated 28 Jun 2006)

Get a UTC time using standard C time function, convert UTC time to MATLAB serial date ...

| Watch this File

File Information
Description

UTC time (universal time convention) is used in ANSI-C standard for defining time. This is measured in seconds since 1970, at the Prime Meridian. By definition, UTC does not depend on Daylight Savings Time. The UTC_TIME function uses a C-MEX function to get the System Time in UTC format.

Another function UTC2DATENUM will convert any UTC time to the correct MATLAB serial date number in local time, accounting for Daylight Savings. This is done with the help of the C-function gmtime. Vectors are supported. The difference of the local time from UTC is also provided as an output.

Acknowledgements
This submission has inspired the following:
Get UTC Time, Convert a UTC time to Datenum (both Win32/Linux versions), Convert Time Array to a Datenum Array (Win32)
MATLAB release MATLAB 7.2 (R2006a)
Other requirements MEXW32 files included for Windows. mexCompile script to build for Linux is included.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
04 May 2005 Bulent Bayraktar

Great, Abe! :)

11 Oct 2005 K Reese

Great idea. Clearly mathworks forgot about time zone conversions. However, your function does not handle arrays of dates, and it displays an unneeded message in the command window.

08 Jun 2006 Richard Sonnenfeld

Just what I was looking for, but the .dll is for Windows, not Linux. Ah well. This could
be coded native to Matlab -- It's just a pain in the neck. Was hoping someone else did it!

21 Jun 2006 Richard Sonnenfeld

Worked through the issues of how to use this in Linux. If .mex these
C-functions. (In Linux do e.g.
mex -lm -o utc_time.mexglx utc_time.c) ,
then you don't need the DLL at all. Just use the two m-files and two c-files provided and it just works! Thank you Dr. Cohn!

03 Nov 2006 ralph habib

i want to convert real time to GPs time..can u help?and i tried to download but..it didn't work..if u can help plz send mail to ralph_habib@hotmail.com

15 Aug 2007 Klaps Jos

Dear,

I downloaded the file but..it didn't work, see comments of Matlab Command Window below..if u can help plz send mail to jos.klaps@scarlet.be

Command Window:
??? Input argument "din" is undefined.

Error in ==> datepart at 43
[r,c]=size(din);

>>

16 Aug 2007 Abraham Cohn

Hello, in response to Klaps Jos:
I searched the code for "datepart", and it is not part of the submission ... this must be part of your calling code. So to debug your error, please check the syntax of your function "datepart". Thanks, and good luck.

15 Jul 2009 Albert Steiner

Hello everybody
I would recommend using directly java.lang.System.currentTimeMillis
Example: utc_time = java.lang.System.currentTimeMillis;
(assuming you have JAVA installed)

One advantage is also, that it is in milli seconds as required.
Best wishes, Albert

Please login to add a comment or rating.
Updates
28 Jun 2006

By Request:
* Supports VECTORS
* No message to console (time zone diff is provided in 2nd output argument)
* Better help text for troubleshooting local time
* Includes compile script for Linux (mexCompile), courtesy of Nicholas Bercher

Tag Activity for this File
Tag Applied By Date/Time
clock Abraham Cohn 22 Oct 2008 07:44:07
fun Abraham Cohn 22 Oct 2008 07:44:07
utc Abraham Cohn 22 Oct 2008 07:44:07
datenum Abraham Cohn 22 Oct 2008 07:44:07
utilities Abraham Cohn 22 Oct 2008 07:44:07
time Abraham Cohn 22 Oct 2008 07:44:07
time Nimbus Lam 12 May 2009 15:05:59
utc Lennard 20 May 2010 01:36:05

Contact us at files@mathworks.com