Code covered by the BSD License  

Highlights from
Convert between world time zones with daylight saving times

4.66667

4.7 | 3 ratings Rate this file 18 Downloads (last 30 days) File Size: 5.38 KB File ID: #27953
image thumbnail

Convert between world time zones with daylight saving times

by Erwin Mayer

 

19 Jun 2010

This is a very simple yet powerful function to convert a datenum from one timezone to another.

| Watch this File

File Information
Description

As I could find no built-in function nor reliable contribution to achieve that, I had no choice but to write my own, leveraging the GregorianCalendar Java class.
Usage is quite simple:
    targetDST = TimezoneConvert( dn, fromTimezone, toTimezone )

The datenum dn corresponds to the datetime you want to convert. Just specify from which timezone it comes and the target timezone, and you should get the expected result, that takes into account daylight saving time.

Feel free to let me know if I can extend it to support more situations (like Julian Calendar, obviously ;-).

You can get the name of the available timezones using this command:
    TimeZone.getAvailableIDs
after importing the relevant java packages.
    import java.lang.String
    import java.util.* java.awt.*
    import java.util.Enumeration

MATLAB release MATLAB 7.4 (R2007a)
Other requirements Java
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
07 Jul 2010 K E

Seems to crash because the following mfiles are not included:
year
month
day
hour
minute
second
Or have I misunderstood how to run this?
t1 = TimezoneConvert(now, 'UTC', 'US/Eastern')

07 Jul 2010 Erwin Mayer

Hi K E, from what I could see these functions are normally part of the Financial Toolbox. Aren't they enabled by default?

09 Jul 2010 K E

OK, that's why - I don't have the Financial Toolbox.
Thanks, KE

14 Feb 2011 David Goldsmith

"Feel free to let me know if I can extend it to support more situations"

Well, since K E wasn't explicit: can you make it Financial-Toolbox-free (i.e., not dependent on having that)?

04 Aug 2011 Justinas

This function does not seem to adjust historical time for the DST, does it?

04 Aug 2011 Erwin Mayer

Hi Justinas, it should adjust historical time for the DST, that was the purpose. At least provided the functions from the Java package support them (probably not for dates very far away) Let me know if it does not work with a special case.

19 Jan 2012 David

thank you!

29 Mar 2012 Yuxiao Qin

Thank you so much for the file... I was always working on APIs, which cannot display historical DST... Never thought matlab itself can do the job... Much appreciation!

23 Apr 2012 Matt Aldrich

What about vectorized support?

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
communications Erwin Mayer 21 Jun 2010 11:42:23
gmt Erwin Mayer 21 Jun 2010 11:42:23
local time Erwin Mayer 21 Jun 2010 11:42:23
time zone Erwin Mayer 21 Jun 2010 11:42:23
time zones Erwin Mayer 21 Jun 2010 11:42:23
travel Erwin Mayer 21 Jun 2010 11:42:23
convert Erwin Mayer 21 Jun 2010 11:42:23
dst Erwin Mayer 21 Jun 2010 11:42:23
daylight Erwin Mayer 21 Jun 2010 11:42:23
daylight saving time Erwin Mayer 21 Jun 2010 11:42:23
utc Erwin Mayer 21 Jun 2010 11:42:23
local time A.J. Geissler 16 Sep 2011 05:46:00

Contact us at files@mathworks.com