CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Formatting date

  1. #1
    Join Date
    May 1999
    Posts
    318

    Formatting date

    I want to display date in local system format.
    For example : dd/mm/yyyy for france and mm/dd/yyyy for us.

    I try the following code but it didn't work :


    CTime time = CTime::GetCurrentTime();
    CString strDate = time.Format(_T("%x"));




    In fact this code ALWAYS results in : mm/dd/yyyy

    Please help




  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Formatting date

    Have you changed your locale settings in Regional Settings ?


  3. #3
    Join Date
    May 1999
    Posts
    318

    Re: Formatting date

    Yes I have.
    Therefore a customer test with england local settings and the problem is identical.

    Note : The systems used are NT or w98.



  4. #4
    Guest

    Re: Formatting date

    Can you not do

    date.format(%d/%m/%y);


  5. #5
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Formatting date

    I've tested here at my portable. And I have the same problem.


  6. #6
    Join Date
    Apr 1999
    Location
    Sussex, England
    Posts
    49

    Re: Formatting date

    Try this.


    COleDateTime timeNow;
    timeNow = COleDateTime::GetCurrentTime();
    CString strDate = timeNow.Format(VAR_DATEVALUEONLY);
    CString strTime = timeNow.Format(VAR_TIMEVALUEONLY);





  7. #7
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: Formatting date

    Hi,
    I think you may have to get around this problem by reading the settings from the registry used by the current user.
    If you look at the key
    [HKEY_CURRENT_USER\Control Panel\International]

    The sub-key "sShortDate"="M/d/yyyy" tells you what format you would be required to display your date in. You would only have to parse this to get the information you need.

    HTH


    Roger Allen
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  8. #8
    Join Date
    May 1999
    Posts
    4

    Re: Formatting date

    First of all: Skip CTime! COleDateTime will last for quite a while longer.

    Then, formatting as regional settings can be done like this:
    COleDateTime dt;
    CString szDate;

    szDate = dt.Format(VAR_DATEVALUEONLY , LANG_USER_DEFAULT);

    // and the other way around

    dt.ParseDateTime( szDate, VAR_DATEVALUEONLY, LANG_USER_DEFAULT );




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