GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 4:54 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: World Clock using GTimeZone
PostPosted: Fri Apr 26, 2013 1:50 am 
Offline
GTK+ Geek

Joined: Wed Mar 18, 2009 2:26 pm
Posts: 62
Iam designing a world clock application to display 5 timezone including the local time zone. I know by using ...
g_date_time_new_now_local() and g_date_time_get_timezone_abbreviation() to get the locale time or date and the timezone.
But i need to also get the other times? How do i do this?
I have put a snippet of the code... I am in Tokyo Japan. the first g_print shows the correct time and JST as the zone.
But when i try to recompute it it shows UTC time???

Code:
#include <gtk/gtk.h>

int main (int argc,char *argv[])
{
    gtk_init (&argc, &argv);
    GTimeVal time;
    g_get_current_time(&time);
//     g_time_val_from_iso8601(tmp_time, &time);
    GDateTime * my_datetime = g_date_time_new_now_local();
    gchar * my_time = g_date_time_format(my_datetime, "%H:%M");
    g_print("%s %s\n", my_time, g_date_time_get_timezone_abbreviation(my_datetime));
    g_free(my_time);
    g_date_time_unref(my_datetime);

    GTimeZone * new_zone = g_time_zone_new("JP");
    GDateTime * new_datetime = g_date_time_new_now(new_zone);
    gchar * new_time = g_date_time_format(new_datetime, "%H:%M");
    g_print("%s %s\n", new_time, g_date_time_get_timezone_abbreviation(new_datetime));
    g_free(new_time);
    g_date_time_unref(new_datetime);
    g_time_zone_unref(new_zone);

  return 0;
}


Thanks in advance.

_________________
Hello, העלו, Здравствулте!


Top
 Profile  
 
 Post subject: Re: World Clock using GTimeZone
PostPosted: Fri Apr 26, 2013 6:33 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 767
Location: UK
Hello,

On my system "JP" is not a valid time zone and hence why it has reverted to UTC. "JP" is the country code and does not work with time zones.

For my system valid time zones for the area you want is "Japan" or "Asia/Tokyo".

For your information Glib looks for the time zone information in /usr/share/zoneinfo or if the environment variable TZDIR is set it looks at the directory store there.

_________________
E.


Top
 Profile  
 
 Post subject: Re: World Clock using GTimeZone
PostPosted: Tue Apr 30, 2013 1:10 am 
Offline
GTK+ Geek

Joined: Wed Mar 18, 2009 2:26 pm
Posts: 62
Hello

Thanks for that .. it works now.
But now if other new timezone is set to EST it shows me the EST time but without Daylight Saving?

_________________
Hello, העלו, Здравствулте!


Top
 Profile  
 
 Post subject: Re: World Clock using GTimeZone
PostPosted: Tue Apr 30, 2013 6:00 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 767
Location: UK
The information held on EST does not deal with day light saving, as EST is used by many areas that do or do not use day light saving. See http://en.wikipedia.org/wiki/Eastern_Time_Zone. Those areas that have daylight saving switch to EDT when needed. All that EST is is UTC (GMT) -5 hours.

So if you need the time zone information for New York you would use "America/New_York" and not "EST"

_________________
E.


Top
 Profile  
 
 Post subject: Re: World Clock using GTimeZone
PostPosted: Wed May 01, 2013 4:08 am 
Offline
GTK+ Geek

Joined: Wed Mar 18, 2009 2:26 pm
Posts: 62
okokkok That worked .. as you said wrong timezone :)
Thank you

_________________
Hello, העלו, Здравствулте!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group