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. Date Conversion

Date Conversion

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 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.
  • L Offline
    L Offline
    Lilian Chan Grant
    wrote on last edited by
    #1

    The following code: // Get file accessed date from _stat struct _stat buff; _tstat ( (TCHAR*)m_szFilePath, &buff); TCHAR* l_szTime = _tctime(&buff.st_atime); TCHAR* p_eol = _tcsstr(l_szTime, _T("\n")); // Remove the '\n' from the end of the returned string from atime. *p_eol = L'\0'; // Return the file accessed date. *p_szDate = (_bstr_t) l_szTime; produces Fri Dec 07 11:23:13 2001. Does anyone know how to get the prettier way Properties does it? (Today, December 7, 2001, 11:23 AM) Please let me know if there is such a way. If not, does someone know of any code that does the formatting? Thanks, Lilian

    M 1 Reply Last reply
    0
    • L Lilian Chan Grant

      The following code: // Get file accessed date from _stat struct _stat buff; _tstat ( (TCHAR*)m_szFilePath, &buff); TCHAR* l_szTime = _tctime(&buff.st_atime); TCHAR* p_eol = _tcsstr(l_szTime, _T("\n")); // Remove the '\n' from the end of the returned string from atime. *p_eol = L'\0'; // Return the file accessed date. *p_szDate = (_bstr_t) l_szTime; produces Fri Dec 07 11:23:13 2001. Does anyone know how to get the prettier way Properties does it? (Today, December 7, 2001, 11:23 AM) Please let me know if there is such a way. If not, does someone know of any code that does the formatting? Thanks, Lilian

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Lilian Chan wrote: If not, does someone know of any code that does the formatting? GetDateFormat() and GetTimeFormat() format dates/times using the user's language and regional settings automatically. --Mike-- http://home.inreach.com/mdunn/ Help! Help! I'm being repressed!! :love: your :bob: with :vegemite: and :beer: Sonork - 100.10414 AcidHelm

      N L 2 Replies Last reply
      0
      • M Michael Dunn

        Lilian Chan wrote: If not, does someone know of any code that does the formatting? GetDateFormat() and GetTimeFormat() format dates/times using the user's language and regional settings automatically. --Mike-- http://home.inreach.com/mdunn/ Help! Help! I'm being repressed!! :love: your :bob: with :vegemite: and :beer: Sonork - 100.10414 AcidHelm

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Now you tell me!:-D Just the other day I was trying to do the same thing and couldn't remember the function. I ended up using strftime. Still works but I wanted GetDateFormat()

        1 Reply Last reply
        0
        • M Michael Dunn

          Lilian Chan wrote: If not, does someone know of any code that does the formatting? GetDateFormat() and GetTimeFormat() format dates/times using the user's language and regional settings automatically. --Mike-- http://home.inreach.com/mdunn/ Help! Help! I'm being repressed!! :love: your :bob: with :vegemite: and :beer: Sonork - 100.10414 AcidHelm

          L Offline
          L Offline
          Lilian Chan Grant
          wrote on last edited by
          #4

          Thanks, Mike, for your response. I should have been more specific. I need to take that TCHAR * and convert it to a prettier format. My application needs to display the creation, accessed, and modified dates of a file. If there is no convenience function to convert the date, I guess I'll just have to write my own :( Thanks, Lilian :)

          RaviBeeR M 2 Replies Last reply
          0
          • L Lilian Chan Grant

            Thanks, Mike, for your response. I should have been more specific. I need to take that TCHAR * and convert it to a prettier format. My application needs to display the creation, accessed, and modified dates of a file. If there is no convenience function to convert the date, I guess I'll just have to write my own :( Thanks, Lilian :)

            RaviBeeR Offline
            RaviBeeR Offline
            RaviBee
            wrote on last edited by
            #5

            strftime() /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com

            1 Reply Last reply
            0
            • L Lilian Chan Grant

              Thanks, Mike, for your response. I should have been more specific. I need to take that TCHAR * and convert it to a prettier format. My application needs to display the creation, accessed, and modified dates of a file. If there is no convenience function to convert the date, I guess I'll just have to write my own :( Thanks, Lilian :)

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              If you want your output to conform to the user's locale settings (and you should) you'll need to use something other than stat() (like GetFileTime()), or use CTime which can convert from time_t to SYSTEMTIME. --Mike-- My really out-of-date homepage Buffy's on. Gotta go, bye! Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

              L 1 Reply Last reply
              0
              • M Michael Dunn

                If you want your output to conform to the user's locale settings (and you should) you'll need to use something other than stat() (like GetFileTime()), or use CTime which can convert from time_t to SYSTEMTIME. --Mike-- My really out-of-date homepage Buffy's on. Gotta go, bye! Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

                L Offline
                L Offline
                Lilian Chan Grant
                wrote on last edited by
                #7

                Thanks, Mike and Ravi! With your suggestions, I was able to make my stuff work. It drives me crazy, since it seems so trivial. We have to keep our HMI people happy.

                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