Results 1 to 4 of 4

Thread: How to convert CString to CTime

  1. #1
    Join Date
    Jul 2009
    Posts
    81

    How to convert CString to CTime

    I want to use system's date/time which is in mm/dd/yy format in code. But the problem is that the time that I am getting is not in ate/time format. So I want to change it to CTime format so that I can use it. How is this going to be possible? How can I convert the CString into CTIme format?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to convert CString to CTime

    Code:
    CTime stTime;
    CTime *dynTime;
    
    dynTime = new CTime(cstringYear,cstringMonth,cstringDay,cstringHour,cstringMin,cstringSec,cstringDsT);
    stTime = dynTime;
    delete dynTime;
    In the above code, you call the system time and save it to your "stTime" and then use this variable in your code.

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: How to convert CString to CTime

    Code:
    COleDateTime myDtTime;
    CTime sysTime;
    if(myDtTime.ParseDateTime(strTimestampOther))
    {
          SYSTEMTIME st;
          if(myDtTime.GetAsSystemTime(st))
          {
                sysTime = st;
           }
    }
    else
    ASSERT(FALSE);

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to convert CString to CTime

    I suppose it is not possible to convert a CString object to a CTime object. However if you still want to do so then you can format your time which is in string format into a CTime. You can also divide it into hours, minutes, seconds etc and manually create the CTime object.

Similar Threads

  1. CString vs std:string
    By Jai$Man in forum Software Development
    Replies: 5
    Last Post: 26-06-2011, 07:41 PM
  2. How to convert from ISO to DMG
    By bevan in forum Operating Systems
    Replies: 4
    Last Post: 11-11-2010, 07:47 AM
  3. Finding ctime,mtime and atime
    By John Wilson in forum Operating Systems
    Replies: 5
    Last Post: 12-03-2010, 09:13 PM
  4. C : Implementation of ctime()
    By Gavyn in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 04:21 PM
  5. Replies: 1
    Last Post: 26-07-2008, 02:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,123,339.75825 seconds with 17 queries