Re: [Vala] Time in vala
- From: Jürg Billeter <j bitron ch>
- To: Karl Lattimer <karl qdh org uk>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Time in vala
- Date: Tue, 09 Dec 2008 00:29:16 +0100
On Tue, 2008-12-02 at 15:06 +0000, Karl Lattimer wrote:
I can never find enough documentation about time in vala :( so I'm going
to ask a bunch of questions here... Maybe I'll add a GNOME live page
when I've got the important stuff done... God knows I already want to
update the GTK/Cairo stuff to be more detailed.
Anyway.
I need to turn a timestamp into a string, but I can't seem to see how to
do this... Something like
int timestamp = "1234151912"; // whatever...
var time = new Time;
string date_string = Time.strftime("%s", timestamp);
// an output like yyyy-mm-dd hh:mm would be nice..
I can never seem to read the time vapi stuff properly :/
There is no proper time API in GLib, unfortunately. That's the reason
why Vala is also lacking a bit in that area. I've improved the situation
a bit in trunk now.
time_t timestamp = 1234151912;
var t = Time.gm (timestamp);
// returns time in RFC 3339 format: 2009-02-09 03:58:32
string date_string = t.to_string ();
// returns time in custom format, see strftime manpage
// for example, Mon Feb 9 03:58:32 2009
string custom_string = t.format ("%c");
A little introduction to using the features of time would be really
nice, I've got to do a whole load of calculations e.g. convert a
timestamp to a nearest month, day, hour etc... then build a scale of
various months/days/hours near by... I need to convert things back and
forth between timestamps and do things like add one day and get the
timestamp for that etc...
Conversion from time_t to GLib.Time:
var t = Time.gm (timestamp)
Conversion from GLib.Time to time_t:
time_t timestamp = t.mktime ();
Add one day to a timestamp:
timestamp += 24 * 3600;
HTH,
Jürg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]