Yun - How display a unix date format ?

Hi everybody !

I have a simple question. I don’t find the solution… Shame on me :blush:
I have an Arduino Yun. I would like to display time like this : 2014-01-06T12:45:15.000Z

Here is my code :

#include <FileIO.h>

void setup() {
  // Initialize the Bridge and the Serial
  Bridge.begin();
  Serial.begin(9600);
  FileSystem.begin();
  while(!Serial);  // wait for Serial port to connect.
}

void loop () {
  // make a string that start with a timestamp for assembling the data to log:
  String dataString;
  dataString += getTimeStamp();
 Serial.println(dataString);
   delay(5000);
}

// This function return a string with the time stamp
String getTimeStamp() {
  String result;
  Process time;
  // date is a command line utility to get the date and the time 
  // in different formats depending on the additional parameter 
  time.begin("date");
  time.addParameter("+%F%T"); 
  time.run();  // run the command

  // read the output of the command
  while(time.available()>0) {
    char c = time.read();
    if(c != '\n')
      result += c;
  }
  return result;
}

Here is the parameters : http://en.wikipedia.org/wiki/Date_(Unix)
But I couldn’t find how to display like this : 2014-01-06T12:45:15.000Z

Do you have an idea ?

Thanks !

I’m sure there is a better way but try something like:

#include <Process.h>

void setup() {
  Bridge.begin();	// Initialize the Bridge
  Serial.begin(115200);	// Initialize the Serial

  // Wait until a Serial Monitor is connected.
  while (!Serial);
}

void loop() {
  String result;
  Process time;
   time.runShellCommand("echo `date +%F`T`date +%T`Z");

  // do nothing until the process finishes, so you get the whole output:
  while (time.running());

  // Read command output. 
  while(time.available()>0) {
    char c = time.read();
    if(c != '\n')
      result += c;
  }
  Serial.println(result);
  delay(10000);  // wait 10 seconds before you do it again
}

Thanks for your help ! Works very well !