Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a value such as 'timestamp' below, where the last three digits correspond to milliseconds.

timestamp = 1340830988768

I currently have code that looks like the following:

import indicate
indicator = indicate.Indicator()
indicator.set_property_time("time", int(timestamp[:-3]))

I want to amend it to use:

from gi.repository import Indicate
indicator = Indicate.Indicator()

However, the new version of set_property_time requires the second parameter to be a GLib.TimeVal. How do I create a GLib.TimeVal from my timestamp? Millisecond precision is not important for this application.

share|improve this question

This is what I came up with, maybe it is of any help:

>>> from gi.repository import GLib, Indicate
>>> timestamp = '1340830988768'
>>> indicator = Indicate.Indicator()
>>> timeval = GLib.TimeVal()
>>> timeval.tv_sec = int(timestamp[:-3])
>>> indicator.set_property_time("time", timeval)

Do note this section in the GLib reference manual:

GLib is attempting to unify around the use of 64bit integers to represent microsecond-precision time. As such, this type will be removed from a future version of GLib.

share|improve this answer
Thank you! I think this is what I need, but I can't confirm until I fix some other issues with my code. – 8128 Jul 3 '12 at 12:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.