Date and time [solved]

I'm going crazy to set time with Time.h. How I setup date and time ?
Someone know any library works better?

Thanks for yours answers...

I'm going crazy to set time with Time.h.

Where's your code? What is not working? What proof do you have that it (whatever it is) isn't working?

Someone know any library works better?

Better than what? An ice scraper?

time.h works very well for me although there was a bit of a learning curve.

The simplest example below wants you to send it a unix time over serial( like T1262347200) and then it will run a display in digital clock form.

Have you tried it?

/* 
 * TimeSerial.pde
 * example code illustrating Time library set through serial port messages.
 *
 * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
 * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010
 T1262347200  
 *
 * A Processing example sketch to automatically send the messages is inclided in the download
 */ 
 
#include <Time.h>  

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 

void setup()  {
  Serial.begin(9600);
  setSyncProvider( requestSync);  //set function to call when sync required
  Serial.println("Waiting for sync message");
}

void loop(){    
  if(Serial.available() ) 
  {
    processSyncMessage();
  }
  if(timeStatus()!= timeNotSet)   
  {
    digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh  
    digitalClockDisplay();  
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ; 
    Serial.print(c);  
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();          
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number    
        }
      }   
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    }  
  }
}

time_t requestSync()
{
  Serial.print(TIME_REQUEST,BYTE);  
  return 0; // the time will be sent later in response to serial mesg
}

This was my next effort after the serial example. iit's self contained and you may find it easier to follow.

#include <Time.h>  

void setup()  {
  Serial.begin(115200);
  Serial.println("Testing Time Setting Functions");
  setTime(1262347200); // seconds since jan 1 1970
  digitalClockDisplay();  
  setTime(12,0,0,1,1,2010); // another way to set the time setTime(hr,min,sec,day,month,yr)
  digitalClockDisplay();    
}

void loop(){   
 delay(10000);
 digitalClockDisplay();    
 
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

bill2009:
This was my next effort after the serial example. iit's self contained and you may find it easier to follow.

  setTime(1262347200); // seconds since jan 1 1970

setTime(12,0,0,1,1,2010); // another way to set the time setTime(hr,min,sec,day,month,yr)

Thanks a lot for yours answers. This two functions are that I looking for but when I tried to use don't work me.
If you think that I don't found in google or in arduino documentation are wrong.

Thanks.

p.d: When I say work better I would say most easier to use.

If you copy and paste my second examPle into a sketch what result do you get?