GLib.DateTime is the right way to do this, and it's a little strange that you are requesting local time and then converting it to unix time (which is implicitly converted to UTC). However, the real problem is that you combine milliseconds (1 / 1000th of a second) and microseconds (1/1000000 seconds per second). So change the last line to
var msec = (sec * 1000) + (now.get_microsecond () / 1000);
Alternatively, it is easier to use GLib.get_real_time :
int64 msec = GLib.get_real_time () / 1000;
(. GLib.get_monotonic_time