Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. C / C++ / MFC
  3. COleDateTimeSpan wierdness....

COleDateTimeSpan wierdness....

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Liam OHagan
    wrote on last edited by
    #1

    Can anyone tell me why the following code does what it does: (Note that the code has been trivialised for readability :)) ZeroTime.SetDateTime( 1970, 1, 1, 0, 0, 0 ); OtherTime.SetDateTime(1970, 1, 1, 0, 0, 10); COleDateTimeSpan TimeDifference; TimeDifference= (OtherTime - ZeroTime); CString Seconds, TotalSeconds; Seconds.Format("%10d", TimeDifference.GetSeconds()); TotalSeconds.Format("%10d", TimeDifference.GetTotalSeconds()); Seconds.Replace(' ','0'); Seconds.Replace(' ','0'); After all that I get the following output: Seconds = 0000000010 TotalSeconds = 0000000000 Why can't GetTotalSeconds determine the correct number of seconds?? Environment is Visual C++ 6, SP5 on Win NT4 SP6 It's driving me nuts!! Thanks anyone that can help! :-O Senior Test Engineer GLI Australia www.gli.com.au

    K 1 Reply Last reply
    0
    • L Liam OHagan

      Can anyone tell me why the following code does what it does: (Note that the code has been trivialised for readability :)) ZeroTime.SetDateTime( 1970, 1, 1, 0, 0, 0 ); OtherTime.SetDateTime(1970, 1, 1, 0, 0, 10); COleDateTimeSpan TimeDifference; TimeDifference= (OtherTime - ZeroTime); CString Seconds, TotalSeconds; Seconds.Format("%10d", TimeDifference.GetSeconds()); TotalSeconds.Format("%10d", TimeDifference.GetTotalSeconds()); Seconds.Replace(' ','0'); Seconds.Replace(' ','0'); After all that I get the following output: Seconds = 0000000010 TotalSeconds = 0000000000 Why can't GetTotalSeconds determine the correct number of seconds?? Environment is Visual C++ 6, SP5 on Win NT4 SP6 It's driving me nuts!! Thanks anyone that can help! :-O Senior Test Engineer GLI Australia www.gli.com.au

      K Offline
      K Offline
      Kelly Herald
      wrote on last edited by
      #2

      The problem is that you are trying to format the return value of GetTotalSeconds function as if it were an integer. According to MSDN the function is prototyped as a double even though it returns an integer. Try this:    TotalSeconds.Format("%10d", **(int)**TimeDifference.GetTotalSeconds()); This works for me.

      L 1 Reply Last reply
      0
      • K Kelly Herald

        The problem is that you are trying to format the return value of GetTotalSeconds function as if it were an integer. According to MSDN the function is prototyped as a double even though it returns an integer. Try this:    TotalSeconds.Format("%10d", **(int)**TimeDifference.GetTotalSeconds()); This works for me.

        L Offline
        L Offline
        Liam OHagan
        wrote on last edited by
        #3

        Yes, thanks for the info, I ended up doing this: long Difference = (long)TimeDifference.GetTotalSeconds(); TotalSeconds.Format(("%10d", Difference); (or something similar anyway). No need to tear my hair out anymore! Thanks for the info! Regards Senior Test Engineer GLI Australia www.gli.com.au

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups