• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

ADVERTISEMENT

Volume Number: 16 (2000)
Issue Number: 4
Column Tag: Tips and Tidbits

Tips and Tidbits

by Jeff Clites (online@mactech.com)

The Difference Between Unix and Mac OS Time Epochs

The Mac OS system clock returns a count which is an integer number of seconds since 00:00 1st January 1904, expressed in local time, while the UNIX system time is also an integer number of seconds, but measured from 00:00 1st January 1970, and expressed in GMT. The difference between these two epochs is 2,082,844,800 seconds plus your time zone offset. Thus, to convert a Mac OS system clock value to a UNIX system clock value, just subtract the sum of this number and your time zone offset in seconds, and to convert the other way, add this number and your time zone offset. For those who prefer to think in code:

enum { UNIXEpochOffset = 2082844800, };

MachineLocation  Here;
SInt32  GMTOffset;
UInt64  MacOSTime, UNIXTime;

ReadLocation(&Here);
GMTOffset =
			Here.delta & 0x00FFFFFF
		|
		((Here.delta & 0x00800000) != 0 ? 0xFF000000 : 0);

/* converting Mac OS time to UNIX time: */
UNIXTime = MacOSTime - UNIXEpochOffset - GMTOffset;

/* converting UNIX time to Mac OS time: */
MacOSTime = UNIXTime + UNIXEpochOffset + GMTOffset;

Note my use of UInt64 instead of UInt32 for the actual time values. This is to avoid any future year-2040 problems with the code. Of course, to be fully year-2040-compliant, you should use the UTCUtils routines present in Mac OS 9 and later. I'll leave the issue of getting a value for Mac OS Time out of those routines as an exercise for the reader. :)

Lawrence D'Oliveiro
ldo@geek-central.gen.nz

Standard File & Appearance

Navigation Services are nice, but your program may still need to run on a system version, like Mac OS 8.1, where it is not installed. In this case you have to fall back on Standard File. But, why not give the Standard File dialogs a more Appearance-compatible look? You can do this without writing any code: just add a 'dlgx' resource or two to your application, and the Appearance Manager will do the rest. Specifically, use the following Rez resource definition:

resource 'dlgx' (-6042, purgeable)
{
	versionZero
	{
		kDialogFlagsUseThemeBackground 
			| kDialogFlagsUseThemeControls
	}
};

This will add an Appearance look to StandardGetFile, while the same definition, with the ID changed to -6043, will add Appearance to StandardPutFile.

Of course, these resources will have no effect if the Appearance Manager is not present.

Lawrence D'Oliveiro
ldo@geek-central.gen.nz

 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live