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. General Programming
  3. C / C++ / MFC
  4. stupid VC++ with timestamp

stupid VC++ with timestamp

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasetutorialquestion
12 Posts 4 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.
  • T tataxin

    I have a dialog with 2 Date Time Picker. The first is m_date with Short Date format The second is m_time with Time format

    CDateTimeCtrl dateBox; // Date Time Picker with Short Date format
    CDateTimeCtrl timeBox; // Date Time Picker with Time format

    Then I want to get the timestamp from them, the final result should be in __int64 (to compare with database and something else). An example is 1214878775000 for a SYSTEMTIME wYear 2008 wMonth 7 wDayOfWeek wDay 1 wHour 11 wMinute 19 wSecond 35 wMilliseconds 734 Try to look at the MSDN, there are many stupid things: CTime, SYSTEMTIME, FILETIME, .... blah blah .... with a alot of functions. Is it really that difficult or I go the wrong way? Does anyone have some way to to this? Here I got the result with a function like this way:

    __int64 CMyDlg::getTimestamp()
    {
    __int64 nTime;

    CTime tmpTime;
    int nYear, nMonth, nDay, nHour, nMin, nSec;
    
    dateBox.GetTime( tmpTime );
    nYear = tmpTime.GetYear(); nMonth = tmpTime.GetMonth(); nDay = tmpTime.GetDay();
    
    timeBox.GetTime( tmpTime );
    nHour = tmpTime.GetHour(); nMin = tmpTime.GetMinute(); nSec = tmpTime.GetSecond();
    
    CTime navTime( nYear, nMonth, nDay, nHour, nMin, nSec );
    
    SYSTEMTIME	ST;
    FILETIME	FT;
    
    navTime.GetAsSystemTime(ST);
    
    SystemTimeToFileTime(&ST,&FT);
    
    \_\_int64 nSetTime;
    
    
    memcpy(&nSetTime, &FT, sizeof(FILETIME));
    
    MyFormatter formatter;
    
    nTime = formatter.FileTimeToJavaTime(nSetTime);
    
    nTime -= 9 \* 60 \* 60\* 1000;
    
    return nTime;
    

    }

    It use another class MyFormatter that I cannot understand. I really hate these stupid stuff !!! :mad: Does anyone have a simple way to get timestamp? Thank you in advance,

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    While it's not completely portable, have you tried:

    SystemTimeToFileTime(&ST,&FT);

    __int64 *nTime = (__int64 *) &FT;

    return *nTime;

    "Love people and use things, not love things and use people." - Unknown

    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

    T 1 Reply Last reply
    0
    • T tataxin

      I have a dialog with 2 Date Time Picker. The first is m_date with Short Date format The second is m_time with Time format

      CDateTimeCtrl dateBox; // Date Time Picker with Short Date format
      CDateTimeCtrl timeBox; // Date Time Picker with Time format

      Then I want to get the timestamp from them, the final result should be in __int64 (to compare with database and something else). An example is 1214878775000 for a SYSTEMTIME wYear 2008 wMonth 7 wDayOfWeek wDay 1 wHour 11 wMinute 19 wSecond 35 wMilliseconds 734 Try to look at the MSDN, there are many stupid things: CTime, SYSTEMTIME, FILETIME, .... blah blah .... with a alot of functions. Is it really that difficult or I go the wrong way? Does anyone have some way to to this? Here I got the result with a function like this way:

      __int64 CMyDlg::getTimestamp()
      {
      __int64 nTime;

      CTime tmpTime;
      int nYear, nMonth, nDay, nHour, nMin, nSec;
      
      dateBox.GetTime( tmpTime );
      nYear = tmpTime.GetYear(); nMonth = tmpTime.GetMonth(); nDay = tmpTime.GetDay();
      
      timeBox.GetTime( tmpTime );
      nHour = tmpTime.GetHour(); nMin = tmpTime.GetMinute(); nSec = tmpTime.GetSecond();
      
      CTime navTime( nYear, nMonth, nDay, nHour, nMin, nSec );
      
      SYSTEMTIME	ST;
      FILETIME	FT;
      
      navTime.GetAsSystemTime(ST);
      
      SystemTimeToFileTime(&ST,&FT);
      
      \_\_int64 nSetTime;
      
      
      memcpy(&nSetTime, &FT, sizeof(FILETIME));
      
      MyFormatter formatter;
      
      nTime = formatter.FileTimeToJavaTime(nSetTime);
      
      nTime -= 9 \* 60 \* 60\* 1000;
      
      return nTime;
      

      }

      It use another class MyFormatter that I cannot understand. I really hate these stupid stuff !!! :mad: Does anyone have a simple way to get timestamp? Thank you in advance,

      K Offline
      K Offline
      kcynic
      wrote on last edited by
      #3

      it due to what you want to. but for the code you provided, i think it will not work, although i didn't look it completely. for example, dateBox.GetTime( tmpTime ); may not retrieve the right time value you want, it due to how the funtion you implemented. btw, you can select CTime to work for you, but time_t, and there are many other time types available, like you used.

      T 1 Reply Last reply
      0
      • K kcynic

        it due to what you want to. but for the code you provided, i think it will not work, although i didn't look it completely. for example, dateBox.GetTime( tmpTime ); may not retrieve the right time value you want, it due to how the funtion you implemented. btw, you can select CTime to work for you, but time_t, and there are many other time types available, like you used.

        T Offline
        T Offline
        tataxin
        wrote on last edited by
        #4

        I think because there're many types, so it makes me confused. I just want to use the simple way, ;) And, dataBox.GetTime(tmpTime) works, I get the correct value I need

        K 1 Reply Last reply
        0
        • D David Crow

          While it's not completely portable, have you tried:

          SystemTimeToFileTime(&ST,&FT);

          __int64 *nTime = (__int64 *) &FT;

          return *nTime;

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          T Offline
          T Offline
          tataxin
          wrote on last edited by
          #5

          thank you, DavidCrow it works, and a little bit better. but I mean, here is the progress: from dialog item -> CTime variable -> another CTime var -> SYSTEMTIME var -> FILETIME var -> __int64 result well, I think it's too much. It's too complex for newbie in VC++, also. And the most is: is it really necessary to be like that??? Do you have a simplier solution for this? Does anyone have? thank you very much, :)

          modified on Tuesday, July 1, 2008 1:17 AM

          D A 2 Replies Last reply
          0
          • T tataxin

            I think because there're many types, so it makes me confused. I just want to use the simple way, ;) And, dataBox.GetTime(tmpTime) works, I get the correct value I need

            K Offline
            K Offline
            kcynic
            wrote on last edited by
            #6

            yes. i did say dataBox.GetTime(tmpTime) may not work, i used 'may', not 'must'. lol. it due to your implement, if you use its inner point, of course it work, right? lol

            T 1 Reply Last reply
            0
            • K kcynic

              yes. i did say dataBox.GetTime(tmpTime) may not work, i used 'may', not 'must'. lol. it due to your implement, if you use its inner point, of course it work, right? lol

              T Offline
              T Offline
              tataxin
              wrote on last edited by
              #7

              you're right, :) so i'm lucky because it works, even I don't know what is inner point, :(. I just let dataBox is the member of the dialog. can you show me the document about inner point so I can read about it. thank you, kcynic, ;)

              K 1 Reply Last reply
              0
              • T tataxin

                thank you, DavidCrow it works, and a little bit better. but I mean, here is the progress: from dialog item -> CTime variable -> another CTime var -> SYSTEMTIME var -> FILETIME var -> __int64 result well, I think it's too much. It's too complex for newbie in VC++, also. And the most is: is it really necessary to be like that??? Do you have a simplier solution for this? Does anyone have? thank you very much, :)

                modified on Tuesday, July 1, 2008 1:17 AM

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                tataxin wrote:

                Do you have a simplier solution for this?

                Not by much. What about:

                __int64 CMyDlg::getTimestamp( void )
                {
                SYSTEMTIME stDate;
                m_date.GetTime(&stDate);

                SYSTEMTIME stTime;
                m\_time.GetTime(&stTime);
                
                stDate.wHour   = stTime.wHour;
                stDate.wMinute = stTime.wMinute;
                stDate.wSecond = stTime.wSecond;
                
                FILETIME ft;
                SystemTimeToFileTime(&stDate, &ft);
                
                \_\_int64 \*nTime = (\_\_int64 \*) &ft;
                
                return \*nTime;
                

                }

                "Love people and use things, not love things and use people." - Unknown

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                T 1 Reply Last reply
                0
                • T tataxin

                  thank you, DavidCrow it works, and a little bit better. but I mean, here is the progress: from dialog item -> CTime variable -> another CTime var -> SYSTEMTIME var -> FILETIME var -> __int64 result well, I think it's too much. It's too complex for newbie in VC++, also. And the most is: is it really necessary to be like that??? Do you have a simplier solution for this? Does anyone have? thank you very much, :)

                  modified on Tuesday, July 1, 2008 1:17 AM

                  A Offline
                  A Offline
                  Alan Balkany
                  wrote on last edited by
                  #9

                  You're right. It's way too complex. The insane complexity started with MFC in the mid/late 1990s. I think Java became popular around then because people were disgusted with the complex crap from Microsoft. In response, Microsoft created a more sane platform, C# and .NET, copying a lot from Java. The simpler solution is to switch to C#. It's amazing how much simpler everything is in C#.

                  T 1 Reply Last reply
                  0
                  • D David Crow

                    tataxin wrote:

                    Do you have a simplier solution for this?

                    Not by much. What about:

                    __int64 CMyDlg::getTimestamp( void )
                    {
                    SYSTEMTIME stDate;
                    m_date.GetTime(&stDate);

                    SYSTEMTIME stTime;
                    m\_time.GetTime(&stTime);
                    
                    stDate.wHour   = stTime.wHour;
                    stDate.wMinute = stTime.wMinute;
                    stDate.wSecond = stTime.wSecond;
                    
                    FILETIME ft;
                    SystemTimeToFileTime(&stDate, &ft);
                    
                    \_\_int64 \*nTime = (\_\_int64 \*) &ft;
                    
                    return \*nTime;
                    

                    }

                    "Love people and use things, not love things and use people." - Unknown

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    T Offline
                    T Offline
                    tataxin
                    wrote on last edited by
                    #10

                    Oh nice, DavidCrow!! At least we don't have to use CTime. so the process will be from dialog item -> SYSTEMTIME var -> FILETIME var -> __int64 result It works, :) Thank you very much!!

                    1 Reply Last reply
                    0
                    • A Alan Balkany

                      You're right. It's way too complex. The insane complexity started with MFC in the mid/late 1990s. I think Java became popular around then because people were disgusted with the complex crap from Microsoft. In response, Microsoft created a more sane platform, C# and .NET, copying a lot from Java. The simpler solution is to switch to C#. It's amazing how much simpler everything is in C#.

                      T Offline
                      T Offline
                      tataxin
                      wrote on last edited by
                      #11

                      Hahaha, it's a good idea to change to Java or C#, Alan Balkany. But I have no choice in my projects. Just my boss decided it. Anyway, thank you for that, :)

                      1 Reply Last reply
                      0
                      • T tataxin

                        you're right, :) so i'm lucky because it works, even I don't know what is inner point, :(. I just let dataBox is the member of the dialog. can you show me the document about inner point so I can read about it. thank you, kcynic, ;)

                        K Offline
                        K Offline
                        kcynic
                        wrote on last edited by
                        #12

                        dateBox.GetTime( tmpTime ); in this line, you might only want to retrieve a time value from your dialog. what i said inner point means in the tmpTime, if it isn't a CTime object, you should use points the new values and return, otherwise, you can't return the right value via tmpTime, right? especially, for c++ class, there are two copying ways: simple copy and deep copy. Almost every C++ book will refer it, you can look up it.

                        modified on Tuesday, July 1, 2008 11:11 PM

                        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