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. String to time converstion

String to time converstion

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 5 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.
  • Z Offline
    Z Offline
    zahid_ash
    wrote on last edited by
    #1

    Hi, I have a string have data of time format. like strTime = 06:45:18 I want to convert it into time object or store it into time variable , Becuase I want to take the time difference between to time that are actualy first stored in strings thanks Regards.

    _ L 2 Replies Last reply
    0
    • Z zahid_ash

      Hi, I have a string have data of time format. like strTime = 06:45:18 I want to convert it into time object or store it into time variable , Becuase I want to take the time difference between to time that are actualy first stored in strings thanks Regards.

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      Hi You can use the following function size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr ); size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr ); Wishes. Anshuman Dandekar Dare to Dream, Care to Achieve............. -- modified at 3:00 Tuesday 31st January, 2006

      O 1 Reply Last reply
      0
      • _ _AnsHUMAN_

        Hi You can use the following function size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr ); size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr ); Wishes. Anshuman Dandekar Dare to Dream, Care to Achieve............. -- modified at 3:00 Tuesday 31st January, 2006

        O Offline
        O Offline
        Owner drawn
        wrote on last edited by
        #3

        He wants to convert a string object to time.

        Jesus Lives Forever - Amen:rose:

        --Owner drawn:rose: --An eye for an eye makes the whole world blind. --Jesus is Lord:rose:

        Z 1 Reply Last reply
        0
        • O Owner drawn

          He wants to convert a string object to time.

          Jesus Lives Forever - Amen:rose:

          --Owner drawn:rose: --An eye for an eye makes the whole world blind. --Jesus is Lord:rose:

          Z Offline
          Z Offline
          zahid_ash
          wrote on last edited by
          #4

          You are right. String object to time. Do you have any idea how it will be Regards.

          O 1 Reply Last reply
          0
          • Z zahid_ash

            You are right. String object to time. Do you have any idea how it will be Regards.

            O Offline
            O Offline
            Owner drawn
            wrote on last edited by
            #5

            AFAIK you have to write one by yourself. Could be tricky at times.

            Jesus Lives Forever - Amen:rose:

            --Owner drawn:rose: --An eye for an eye makes the whole world blind. --If you find my post helpful then do rate it. --Jesus is Lord:rose:

            1 Reply Last reply
            0
            • Z zahid_ash

              Hi, I have a string have data of time format. like strTime = 06:45:18 I want to convert it into time object or store it into time variable , Becuase I want to take the time difference between to time that are actualy first stored in strings thanks Regards.

              L Offline
              L Offline
              Laxman9
              wrote on last edited by
              #6

              The following code may help u.. i have Created and Debugged demo for U. Assumming that ur using MFC Application CString strTime="06:45:18"; CString h,m,s; SYSTEMTIME st; GetSystemTime(&st); h=strTime.Mid(0,2); m=strTime.Mid(3,2); s=strTime.Mid(6,2); sscanf(h.GetBuffer(2),"%d",&st.wHour); sscanf(m.GetBuffer(2),"%d",&st.wMinute); sscanf(s.GetBuffer(2),"%d",&st.wSecond); CTime t(st); //h.Format("%d:%d:%d",t.GetHour(),t.GetMinute(),t.GetSecond()); //AfxMessageBox(h); best luck. Thanks and Regards Laxman FAILURE is the first step towards SUCCESS :cool:

              D 1 Reply Last reply
              0
              • L Laxman9

                The following code may help u.. i have Created and Debugged demo for U. Assumming that ur using MFC Application CString strTime="06:45:18"; CString h,m,s; SYSTEMTIME st; GetSystemTime(&st); h=strTime.Mid(0,2); m=strTime.Mid(3,2); s=strTime.Mid(6,2); sscanf(h.GetBuffer(2),"%d",&st.wHour); sscanf(m.GetBuffer(2),"%d",&st.wMinute); sscanf(s.GetBuffer(2),"%d",&st.wSecond); CTime t(st); //h.Format("%d:%d:%d",t.GetHour(),t.GetMinute(),t.GetSecond()); //AfxMessageBox(h); best luck. Thanks and Regards Laxman FAILURE is the first step towards SUCCESS :cool:

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

                Since your example uses MFC, why not simplify things by using COleDateTime::ParseDateTime()? For example:

                COleDateTime t;
                t.ParseDateTime("06:45:18", VAR_TIMEVALUEONLY);


                "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

                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