CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191

    CTime construction - confusion

    Hi All,

    I have this code constructing a CTime object

    Code:
    CTime tm(2004,2,14,0,0,0,0);
    When I set my computer timezone to be GMT, I saw the value of tm during debug to be 1076716800.

    But when I set my computer timezone to +8.00 GMT, running the same code gives me the value 1076688000.

    Can someone please explain why the difference in value??

    Regards

    Mustafa
    Last edited by Mustafa; February 14th, 2004 at 12:34 AM.
    ______________________________
    To err is human, it's the computer that causes blunders !!!

    DO: Dazzle me with your intelligence
    DON'T : Confuse me with your bullshit

  2. #2
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    Easy, the difference is 8 hours expressed in seconds.
    The Constructor you chose is a special constructor, as it makes a conversion to UTC. As GMT + 8 is 8 hours ahead of UTC, at least now in the winter, 8 hours are subtracted from the absolute time. See MSDN on this topic!
    The Saviour of the World is a Penguin and Linus Torvalds is his Prophet.

  3. #3
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191
    Hi ReorX,

    First of all thanks for the response.......

    Yes I have been going through MSDN on this subject many times but my assumption is that if I were to force tm to contain that value, I expect it to be initialised with that value. So whether my software is used in China or/and in London it doesn't matter cause all I want to do is to do a comparison for a data created in China with the one created in London. Lets say my application in China transmitted tm to a sever using sockets, another copy of the same software in London initialised tm using the same technique to the the same server. Say my codes in the server needs to do this:-

    Code:
    if(tmLon==tmChina){
         
    
    }
    how would I check that??

    Or is there another way to initialise CTime objects to contain the fixed dates which I need regardless of timezones...

    Or do I need to re-calculate timezones before I do a comparison???

    Regards

    Mustafa
    ______________________________
    To err is human, it's the computer that causes blunders !!!

    DO: Dazzle me with your intelligence
    DON'T : Confuse me with your bullshit

  4. #4
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039
    Is there any chance you can use COleDateTime? Some recommend using COleDateTime as it doesn't seem to do any such conversions. It is supposed to store absolute time values. However depending on how you manipulate the data it is still possible that you might have to make allowances for the different time zones.

  5. #5
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191
    Hi Nelo,

    have considered doing that already...but I have used CTime all over my application...and it's a little hair-raising to think that I would need to change them all in my codes knowing that there are already so many copies being used out there. It is just this new feature that is needed to be added on to the server side that needs to be upgraded...just a little one....is there any other way of using CTime the way I wanted it...I wonder??

    Regards

    Mustafa
    ______________________________
    To err is human, it's the computer that causes blunders !!!

    DO: Dazzle me with your intelligence
    DON'T : Confuse me with your bullshit

  6. #6
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    Hi Mustafa,

    the first thing you need is a common timebase.
    So if somebody enters a value in China lets say at 8:00 and somebody does the same at the very same moment in London (lets say local time 0:00), then both CTime objects will have the same value when they both refer to UTC.
    So you can easily compare them, as they both have the same value.

    So it somewhat depends on what you want to have in your application. If you want to compare 8:00 GMT with 8:00 China and you want them to be equal, then indeed you would be unlucky.
    But I don't think, that you would want to compare local times - you probably need to compare global values and for this, UTC is the one and only practical reference!

    Probably, you should relax and think about the design of your software for some hours. Time is always difficult to handle and time spent during design pays back tenfold!

    Design an internal representation for all time objects (e.g. CTime in UTC) and convert them only to local views when they are either read from somewhere or displayed to the User. Do not introduce local aspects of time into your database or your internal calculations.
    The Saviour of the World is a Penguin and Linus Torvalds is his Prophet.

  7. #7
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191

    Ok Got it

    Hi ReorX and Nelo,

    Thanks for the help, ReorX you've cleared away some bugs in my brains especially my assumptions of what that value in CTime objects represents...Now I understand that for a CTime object constructed in China would have a different absolute value in it to the CTime object created in London but they both represents the same times which is 14th February 2004 Midnight, as in my example in my last posts. The difference in the absolute values only says that its 14th February Midnight in China as compared to 14th February 2004 Midnight in London. Once I got that cleared now I know why I cannot compare absolute values..Ok then off to work...

    Thanks guys....have a great day...

    Regards

    Mustafa
    ______________________________
    To err is human, it's the computer that causes blunders !!!

    DO: Dazzle me with your intelligence
    DON'T : Confuse me with your bullshit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured