Unix Timestamp

Steven M. Bellovin smb at research.att.com
Mon Oct 22 18:57:14 UTC 2001


In message <5.1.0.14.2.20011022123839.05490760 at calamity.wyoming.com>, Brandon H
andeland writes:
>
>Does anyone have a formula to convert a unix time stamp into the current time?
>
>I know it is January 1st, 1970, in UTC format.  Just need some example code.
>
>I'm trying to export some data from a HP/UX box into a MSSQL database and 
>need to use the timestamp feature of MSSQL.
>

How accurate does your conversion need to be?  Do you need timezones?  
Daylight time?

On any Unix system, including the open-source clones, grab a copy of 
ctime.c; its job is to do exactly that.  If you want to approximate the 
answer -- well, there are 86400 seconds/day, and either 365 or 366
days/year.  The remaind when dividing by 86400 is the number of seconds 
into the current day, in UTC.

		--Steve Bellovin, http://www.research.att.com/~smb
		Full text of "Firewalls" book now at http://www.wilyhacker.com





More information about the NANOG mailing list