[Mono-list] Using UNIX timestamps with Mono/C#

Philipp Kern phil@philkern.de
Mon, 30 Aug 2004 15:59:11 +0200

Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Dear Mono users,

do you know of any way to get a UNIX timestamp from a DateTime?
I saw it the other way round in the Posix extensions to Mono.

I tried it with using the Ticks property of the DateTime, but the drift
is just too big for any real use:
public static long UnixTime(DateTime dt)
  DateTime unixEpoch =3D new DateTime(1970,1,1,0,0,0);
  return (dt.Ticks - unixEpoch.Ticks)/10000000;

phil@o2 ~ $ echo "Real timestamp: `date +%s`" && mono ./foo.exe
Real timestamp:      1093874233
Calculated by ticks: 1093881433

I would appreciate any hint to this problem.

Thanks in advance,
Philipp Kern

P.S.: Please copy me on your responses as I am not subscribed to the
list. Thank you.

Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

Version: GnuPG v1.2.4 (GNU/Linux)