You can use the standard C functions like mktime()
But are you sure you need translation?
How would you set the DS3231 time?
You could use this statement (see below), or not?
ds3232.setDateTime(Time.year(), Time.month(), Time.day(), Time.hour(), Time.minute(), Time.second());
And this is what’s done in an Arduino library for the DS1337 & DS3231 to do the UNIX epech time translation into the DS format and back
/**
* Convert from unix timestamp
*/
void DS1337::getTime(unsigned long timestamp, int &year, int &month, int &day, int &hour, int &minute, int &second) {
timestamp-= T2000UTC;
second = (int)(timestamp % 60);
timestamp = timestamp / 60;
minute = (int)(timestamp % 60);
timestamp = timestamp / 60;
hour = (int)(timestamp % 24);
timestamp = timestamp / 24;
year = 0;
int dYear = 0;
if (year % 4 == 0)
dYear = 366;
else
dYear = 365;
while (timestamp >= dYear) {
year++;
timestamp-=dYear;
if (year % 4 == 0)
dYear = 366;
else
dYear = 365;
}
day = (int) timestamp;
int dayMonth[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
month = 0;
while (day > dayMonth[month+1])
month++;
day-=dayMonth[month];
month++;
day++;
}
/**
* Get unix timestamp
*/
unsigned long DS1337::getTimestamp(int year, int month, int day, int hour, int minute, int second) {
unsigned long secMinute = 60;
unsigned long secHour = 60 * secMinute;
unsigned long secDay = 24 * secHour;
unsigned long secYear = 365 * secDay;
int dayMonth[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
// leap years
int leapDays = (year >> 2) + 1;
if (((year & 3) == 0) && month < 3)
leapDays--;
// calculate
return year * secYear + (dayMonth[month-1] + (day-1) + leapDays) * secDay + hour * secHour + minute * secMinute + second + T2000UTC;
}