Getting Time Problem

This is a discussion on Getting Time Problem within the C++ Programming forums, part of the General Programming Boards category; I want to get current time living in Turkey, but when I used following function getting time 3 hour less ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    18

    Lightbulb Getting Time Problem

    I want to get current time living in Turkey, but when I used following function getting time 3 hour less than our time because of that reason adding 3 to currentTime->tm_hour is there anything else I can do? Can I say compiler I am living turkey or some where else, is there any reference for that reason
    Thanx u in advance.

    time(&t);
    currentTime = gmtime( &t);
    currentTime->tm_hour = (currentTime->tm_hour +3 ) %24;

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Use localtime instead of gmtime. When you call time, it returns your local machine time, say 8:00AM. When you are converting to GMT, since you live in Turkey, it needs to subtract 3 hours and it gives you back 5:00AM to which you are manually adding back those 3 hours. The solution is to not call gmtime. (At least that's what I think is happening in your case... not 100% sure)
    Last edited by hk_mp5kpdw; 09-07-2007 at 09:56 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Maybe use localtime() instead of gmtime() ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer problem... i think
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 11-30-2005, 03:45 PM
  2. another problem with catstr() this time
    By the_winky_files in forum C Programming
    Replies: 19
    Last Post: 09-22-2005, 05:20 PM
  3. time problem
    By sand_man in forum C Programming
    Replies: 9
    Last Post: 09-13-2005, 06:59 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM
  5. Problem with time on the board, or is it just me?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-23-2002, 06:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21