North American Network Operators Group

Date Prev | Date Next | Date Index | Thread Index | Author Index | Historical

Re: Unix Timestamp

  • From: Steven M. Bellovin
  • Date: Mon Oct 22 14:59:43 2001

In message <[email protected]>, 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