time_t to str? And question about IDE and eeprom

Hi
How to convert time_t value to normal date (DD-MM-YY) ?

My another question is does the arduino IDE clear eeprom on every sketch upload?

My another question is does the arduino IDE clear eeprom on every sketch upload?

I can answer that one. No. The EEPROM is not modified by uploading.

mm It's strange because when I'm reading eeprom after uploading a sketch it is full of 255 values :confused:
I'm using usbasp to upload sketches maybe that is why its happening ?

I assumed you were using the bootloader. I have no idea if using usbasp to upload will result in the EEPROM being erased.

255 is returned when a cell has been erased. This is the way the processor comes from the factory.

Whatever you find out about the usbasp and EEPROM, please report back. It's very likely someone else will value your experience.

How to convert time_t value to normal date (DD-MM-YY) ?

#include <Time.h>


tmElements_t tempTimeStruct = {
  55, 59, 23, 6, 19, 3, 40};
time_t arduinoTime = 0;

void setup() {
  arduinoTime = makeTime(tempTimeStruct);
  setTime(arduinoTime);
  Serial.begin(9600);
}

void loop() {
  makeDateTimeString();
  delay(1000);
}


void makeDateTimeString(){
  char tempBuff[5];
  char tempString[16];
  byte tempByte = 0;

  strcpy(tempString, "");  

  // Days
  tempByte = day();
  if (tempByte < 10 ) strcat(tempString,"0");
  itoa(tempByte, tempBuff, DEC);
  strcat(tempString, tempBuff);
  strcat(tempString, "-");
  // Months
  tempByte = month();
  if (tempByte < 10 ) strcat(tempString, "0");
  itoa(tempByte, tempBuff, DEC);
  strcat(tempString, tempBuff);
  strcat(tempString, "-");
  // Years
  tempByte = year()-2000;
  if (tempByte < 10 ) strcat(tempString, "0");
  itoa(tempByte, tempBuff, DEC);
  strcat(tempString, tempBuff);
  strcat(tempString, " ");
  // Hours
  tempByte = hour();
  if (tempByte < 10 ) strcat(tempString, "0");
  itoa(tempByte, tempBuff, DEC);
  strcat(tempString, tempBuff);
  strcat(tempString, ":");  
  // Minutes
  tempByte = minute();
  if (tempByte < 10 ) strcat(tempString, "0");
  itoa(tempByte, tempBuff, DEC);
  strcat(tempString, tempBuff);
  strcat(tempString, ".");
  // Seconds
  tempByte = second();
  if (tempByte < 10 ) strcat(tempString, "0");
  itoa(tempByte, tempBuff, DEC);
  strcat(tempString, tempBuff);
  Serial.println(tempString);
}

Thank you but your code is not very redable :slight_smile:
I rewrote my code to use time.h instead of DateTime.h
Time.h has ready to use day(time_t) etc

sounds like you already have it going, but for the benefit of others, you can do this assuming you include <Time.h> and t is a time_t value:

  Serial.print(day(t));
  Serial.print('-');
  Serial.print(month(t));
  Serial.print('-');
  Serial.println(year(t));