0

I need to get modify date from a file.

    CFileStatus stat;
    CFile::GetStatus(strFilePath, stat);

It returns 1585557924 to be CTime. (it look like a timestamp)

    stat.m_mtime

I have a lot of file and I need to get modify date from each file as timestamp then sum all timestamp.

But It cannot convert stat.m_mtime to integer.

   int sum_timestamp = 0;
   sum_timestamp +=  (int)stat.m_mtime;

It error like these.

   'no suitable conversion function from "ATL::CTime"to"int"exists'
FRAME_TH
  • 29
  • 7
  • What kind of integer? Unix-style seconds-since-epoch? JS-style milliseconds-since-epoch? Something else? Is [`GetAsSystemTime()`](https://learn.microsoft.com/en-us/cpp/atl-mfc-shared/reference/ctime-class?view=vs-2019#getassystemtime) sufficient for your use case? – cdhowie May 06 '20 at 18:26
  • "How to convert stat.m_mtime to integer ?" - what do you mean? It *is* an integer. 1585557924 is a perfectly valid integer. How you *interpret* it is a different question. – Jesper Juhl May 06 '20 at 18:28
  • What you have there is the number of seconds since the 'epoch' (1st January 1970), and it is already an integral type (specifically a `time_t`, these days, usually, a `long`). So what did you want to convert it to, and why? – Paul Sanders May 06 '20 at 18:28
  • I try to declare int variable for keeping this value. But it cannot to assign 'm_mtime' to a variable. int sum_timestamp = 0; sum_timestamp = (int)stat.m_mtime; but it error like these 'no suitable conversion function from "ATL::CTime"to"int"exists'. – FRAME_TH May 07 '20 at 03:00

1 Answers1

1

Assuming you are compiling in 64 bits, you can get a unix timestamp from CTime using GetTime(), which is is a __time64_t_ (= __int64 = long long). Ex:

   long long sum_timestamp = 0;
   sum_timestamp += stat.m_mtime.GetTime();
Kiruahxh
  • 1,276
  • 13
  • 30