Thread: Getting Time Problem

  1. #1
    Registered User
    Join Date
    Aug 2007

    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.

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

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    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 08: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
    The edge of the known universe
    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.

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, 04:20 PM
  3. time problem
    By sand_man in forum C Programming
    Replies: 9
    Last Post: 09-13-2005, 05:59 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. Problem with time on the board, or is it just me?
    By biosninja in forum A Brief History of
    Replies: 7
    Last Post: 10-23-2002, 05:45 AM