Version 9 of clock seconds

Updated 2004-12-11 03:57:35

Returns the number of seconds since January 1st, 1970. Also known as "Unix time", "timestamp" or "epoch".

Example:

 clock seconds

on Dec 10 2004, 11:44:22, returns

 1102686262

See also: clock


LV Is the epoch the same on all platforms and operating systems?

MSW Due to the source, at least under unix and windows the epoch is 1970-01-01 @ midnight. Under mac the epoch starts (due to the comments) Midnight Jan 1, 1904. mac/tclMacTime.c adds another tcl_mac_epoch_offset which is initialized by _mac_msl_epoch_offset_ if defined (and 0 otherwise), which I assume brings the Mac epoch in sync with the unix epoch. (I don't have a Mac handy to test...)

FPX Anybody knows the difference between Unix and Macintosh epoch? I was stumbling about this recently, requiring a platform-independent "seconds since epoch" value. Seems like the best we can do is

  set sse [clock seconds]
  if {[string equal $::tcl_platform(platform) "macintosh"]} {
    incr sse <seconds between 1904 1970>
  }

Is the constant simply (negative) 2082844800, i.e., 60*60*24*(365*66+17), 66 years with 17 leap years, or do we also have to factor in some number of leap seconds?


[ Category Command

Category Date and Time ]