Arduino + Processing Data Logger SD

Hi everyone!
I’m new to this forum and to Arduino programming too…

I’m trying to make a data logger but I’m having some troubles…

I got the Arduino UNO and Ethernet Shield and I have to create a Data Logger wich writes Data to an SD card whenever a button is pressed.
In the file Arduino should write which button has been pressed and the time.

Thanks to the documentation and to the examples I’m capable of writing something to the SD whenever the button is pressed using this code

#include <Servo.h>

/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */
 
#include <SD.h>
#include <Time.h>

File myFile;
int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean ledOn = false;
boolean currentButton = LOW;
time_t time = null;


void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    
    myFile = SD.open("test.txt", FILE_WRITE);
  
    // if the file opened okay, write to it:
    if (myFile) 
    {
      Serial.print("Writing to test.txt...");
      myFile.println("CONTEGGIO CLICK BOTTONE");
  	// close the file:
      myFile.close();
      Serial.println("done.");
      time = 
    }
    else
    {
      // if the file didn't open, print an error:
      Serial.println("error opening test.txt");
    }
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   pinMode(switchPin, INPUT);
   pinMode(ledPin, OUTPUT);

   
  if (!SD.begin(4)) 
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  
}

boolean debounce(boolean last)
{
    boolean current = digitalRead(switchPin);
    if(last != current)
    {
      delay(5);
      current = digitalRead(switchPin);
    }
    return current;
}

void loop()
{
  currentButton = debounce(lastButton);
  if(lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    myFile = SD.open("test.txt", FILE_WRITE);
  
    // if the file opened okay, write to it:
    if (myFile) 
    {
      Serial.print("Writing to test.txt...");
      myFile.println("Button clicked");
  	// close the file:
      myFile.close();
      Serial.println("done.");
    }
    else
    {
      // if the file didn't open, print an error:
      Serial.println("error opening test.txt");
    }
  }
  lastButton = currentButton;
  digitalWrite(ledPin, ledOn);

}

and I can sync the time with the PC using processing 2.0 and the example file:

import processing.serial.*;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

public static final short portIndex = 0;  // select the com port, 0 is the first port
public static final String TIME_HEADER = "T"; //header for arduino serial time message 
public static final char TIME_REQUEST = 7;  // ASCII bell character 
public static final char LF = 10;     // ASCII linefeed
public static final char CR = 13;     // ASCII linefeed
Serial myPort;     // Create object from Serial class

void setup() {  
  size(200, 200);
  println(Serial.list());
  println(" Connecting to -> " + Serial.list()[portIndex]);
  myPort = new Serial(this,Serial.list()[portIndex], 9600);
  println(getTimeNow());
}

void draw()
{
  textSize(20);
  textAlign(CENTER);
  fill(0);
  text("Click to send\nTime Sync", 0, 75, 200, 175);
  if ( myPort.available() > 0) {  // If data is available,
    char val = char(myPort.read());         // read it and store it in val
    if(val == TIME_REQUEST){
       long t = getTimeNow();
       sendTimeMessage(TIME_HEADER, t);   
    }
    else
    { 
       if(val == LF)
           ; //igonore
       else if(val == CR)           
         println();
       else  
         print(val); // echo everying but time request
    }
  }  
}

void mousePressed() {  
  sendTimeMessage( TIME_HEADER, getTimeNow());   
}


void sendTimeMessage(String header, long time) {  
  String timeStr = String.valueOf(time);  
  myPort.write(header);  // send header and time to arduino
  myPort.write(timeStr); 
  myPort.write('\n');  
}

long getTimeNow(){
  // java time is in ms, we want secs    
  Date d = new Date();
  Calendar cal = new GregorianCalendar();
  long current = d.getTime()/1000;
  long timezone = cal.get(cal.ZONE_OFFSET)/1000;
  long daylight = cal.get(cal.DST_OFFSET)/1000;
  return current + timezone + daylight; 
}

I’m stuck at this point… :~

Could you please give me some advice?

Thanks a lot!