How to get the current date of a generated local text file?

08 Jul 2010


I use LocalFileSystem to make a text file on the mbed(F: drive with Windows 2000).

I tried successfully the "Hello World!" sample program taken from the section of LocalFileSystem in Handbook. And, I always found the date of a newly generated text file is "2008/01/01 12:00". How can I have the current date/time of a generated file by fopen/fclose ?

Thank you for you help, in advance!


08 Jul 2010

I assume it's because you haven't set the time - check out this link.

09 Jul 2010

Hi Alex, Thank you!

I tried this as like below. But, the date of the generated file is also 2008/01/01 12:00.

Should I do set the time differently?

My code:

#include "mbed.h"
LocalFileSystem local("local");

int main() {

   // setup time structure for Fri, 9 Jun 2010 13:45:30
    struct tm t;
    t.tm_sec = 30;    //37 0-59
    t.tm_min = 45;    //42 0-59
    t.tm_hour = 13;   //11 0-23
    t.tm_mday = 9;   //28 1-31
    t.tm_mon = 6;     //9 0-11
    t.tm_year = 110;  //109 year since 1900
    time_t seconds_d = mktime(&t);

    FILE *fp = fopen("/local/pgx_04L.txt", "w");
    fprintf(fp, "Date %s", ctime(&seconds_d));




content of the above file:




09 Jul 2010

Hi Marutsu, Alex,

Just seen this thread; i'm afraid the local file system has no concept of time, so that is why you are seeing these results despite your excellent efforts!

I'll mark it as a feature request if that would be useful; we'll have a look how we could introduce time in a consistent way so it works across various filesystems to support created/modified dates. But just to be clear, this won't be supported any time soon unfortunately.

Thanks for the reports! I hope you can find a suitable workaround/compromise for now.


12 Jul 2010

Hi Simon,

Thank you for this clarification you wrote regarding this report.

I accept this limitation as our working circumstances on mbed.

In cases of much more eager request we have, I'll contact you again!



19 Oct 2011

Hi, I am new to the mbed system (only working a few days), but I came across the some problem after setting the RTC, i.e. always the same date on the text file on the local file system. Anyway as I will use a SD card to write my text files in the near future, I hope that the file's stamp will be OK on the SD card.

has anybody a feedback on this matter with an SD card?

Many thanks in advance

13 Jun 2012

Hi All, has there been any developments regarding the a date/time stamp for the LocalFileSystem? LocalFileSystem is such a useful feature of the mbed compared with other products it's a shame not to have this valuable extra.