Version 11 of clock seconds

Updated 2004-12-12 07:28:08

Returns the number of seconds since January 1st, 1970, Midnight, in Greenwich (GMT). 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...)

Lars H: It's better to say 00:00 than midnight, since each day also has a midnight at 24:00. But there is also another ambiguity, with respect to the time zone. When I do [clock format 0] I get Thu Jan 01 01:00:00 CET 1970, which seems to indicate that the epoch is from 1970-01-01 T 00:00 Z (i.e., it's the UTC/GMT midnight). Is this true on all platforms which use the 1970 epoch?


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?

Lars H: Alpha does the following [L1 ]:

  # Convert seconds from 'epoch' to the unix epoch (used by 'clock').
  proc ISOTime::fromEpoch {epoch when} {
    global ISOTime::systemEpoch

    if {$epoch == ""} {
      set epoch [set ISOTime::systemEpoch]
    }

    if {$epoch == "unix"} {
      return $when
    } elseif {$epoch == "mac"} {
      set when [expr $when + [clock scan "1904-01-01Z00:00:00"]]
      return [expr $when - [ISOTime::ZoneOffset $when "unix"]]
    } else {
      error "ISOTime error: Unknown epoch \"$epoch\""
    }
  }

Anyway the problem of the mac epoch is 2004 getting rather academic.


RS: Find out what your epoch is, without timezone offset, with

 clock format 0 -gmt 1

[ Category Command

Category Date and Time ]