Convert time_t to System::DateTime ???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PeteOlcott

    Convert time_t to System::DateTime ???

    I need to convert time_t to System::DateTim e. All of the examples that
    I found are either in C# or in the obsolete managed C++ syntax. What
    is the current syntax for converting a (probably 64 bit) time_t value
    to System::DateTim e ???
  • Mark Salsbery [MVP]

    #2
    Re: Convert time_t to System::DateTim e ???


    "PeteOlcott " <PeteOlcott@gma il.comwrote in message
    news:3e1d1cb6-371e-4f86-bb5f-ba58ede93b9d@m3 g2000hsc.google groups.com...
    I need to convert time_t to System::DateTim e. All of the examples that
    I found are either in C# or in the obsolete managed C++ syntax. What
    is the current syntax for converting a (probably 64 bit) time_t value
    to System::DateTim e ???

    time_t t = ...;
    long long filetime = t * 10000000LL + 116444736000000 000LL;
    DateTime datetime = DateTime::FromF ileTimeUtc(file time);
    Console::WriteL ine(datetime.To String());



    Mark

    --
    Mark Salsbery
    Microsoft MVP - Visual C++


    Comment

    • Mark Salsbery [MVP]

      #3
      Re: Convert time_t to System::DateTim e ???

      Here's my source, BTW:

      Converting a time_t Value to a File Time
      The time functions included in the C run-time use the **time_t** type to represent the number of seconds elapsed since midnight, January 1, 1970. The following example converts a **time_t** value to a [FILETIME](/windows/win32/api/minwinbase/ns-minwinbase-filetime).



      Mark

      --
      Mark Salsbery
      Microsoft MVP - Visual C++

      Comment

      • PeteOlcott

        #4
        Re: Convert time_t to System::DateTim e ???

        On Sep 22, 5:45 pm, "Mark Salsbery [MVP]"
        <MarkSalsbery[MVP]@newsgroup.nosp amwrote:
        Here's my source, BTW:
        >
        Converting a time_t Value to a File Timehttp://msdn.microsoft. com/en-us/library/ms724228(VS.85) .aspx
        >
        Mark
        >
        --
        Mark Salsbery
        Microsoft MVP - Visual C++
        Here is the answer that I derived:

        System::DateTim e time_tToSystemD ateTime(time_t tt)
        {
        tm* timeptr = gmtime(&tt);
        DateTime sdt(timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr-
        >tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
        return sdt;
        }

        Comment

        • PeteOlcott

          #5
          Re: Convert time_t to System::DateTim e ???

          On Sep 22, 7:06 pm, PeteOlcott <PeteOlc...@gma il.comwrote:
          On Sep 22, 5:45 pm, "Mark Salsbery [MVP]"
          >
          <MarkSalsbery[MVP]@newsgroup.nosp amwrote:
          Here's my source, BTW:
          >
          Converting a time_t Value to a File Timehttp://msdn.microsoft. com/en-us/library/ms724228(VS.85) .aspx
          >
          Mark
          >
          --
          Mark Salsbery
          Microsoft MVP - Visual C++
          >
          Here is the answer that I derived:
          >
          System::DateTim e time_tToSystemD ateTime(time_t tt)
          {
            tm* timeptr = gmtime(&tt);
            DateTime sdt(timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr-
          >
          >
          >
          tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
            return sdt;
          }- Hide quoted text -
          >
          - Show quoted text -
          Here it is again, (Hopefully with better formatting)

          System::DateTim e time_tToSystemD ateTime(time_t tt)
          {
          tm* timeptr = gmtime(&tt);
          DateTime sdt(timeptr->tm_year + 1900,
          timeptr->tm_mon + 1,
          timeptr->tm_mday,
          timeptr->tm_hour,
          timeptr->tm_min,
          timeptr->tm_sec);
          return sdt;
          }

          Comment

          Working...