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

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


--=-tt38IsjV9ZzU6210S3j7
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.

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBBMzKv7Ro5M7LPzdgRAtcSAKCpEcz6PLKP8yN2Qx74B/tXN5O7XgCfXmi4
L+xgxc29f4y41QFwbTD1UOM=
=o6pL
-----END PGP SIGNATURE-----

--=-tt38IsjV9ZzU6210S3j7--