Converting unix time to ISO 8631 (hh:mm:ss)

Hey guys,
I'm currently using the Adafruit CC3000 library to retrieve internet time and output it in the form of UNIX time. How do I now go about converting it to hh:mm:ss? I'm currently using Time.h with the following code:

unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000;
time_t currentTime = now();
Serial.print (hour());

This is returning the error "redeclaration of 'UINT32 currentTime'"
What am I doing wrong?
Thanks!

unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000;
time_t currentTime = now();

Is there any programming language that allows you to have two variables of the same name at the same scope, regardless of whether they are the same type, or not?

If so, C/C++ are not among them.

How would the issue be fixed? Sorry I’m not great with programming obviously

Just reading his reply without applying any knowledge other than the ability to read, it sounds like one of those variables should have a different name.

so currentTime outputs the unix time that needs to be converted. How would I do that if the variables are different? Wouldn't I need to connect them somehow? Either way, I don't know how to make the conversion

Variables don't get "connected". You do some math on the Unix time and store the results of that math in some variables.

Start with this. Could you do it on paper? How would that work?

Or do you want it in the form of a character string that you can print. You seem to have the Time library, use it.

time_t currentTime = lastPolledTime + (millis() - sketchTime) / 1000;

char buffer[10];
sprintf(buffer, "%02d:%02d:%02d", hour(currentTime), minute(currentTime), second(currentTime));
Serial.println(buffer);  //print to the serial monitor in hh:mm:ss format.

It's really hard to help you here because we don't really know what you want to do. Sure you want time in a certain format, but to do what with it.

Or do you want to have variables for each piece:

int theHours = hour(currentTime);
int theMinutes = minute(currentTime);
int theSeconds = second(currentTime);

abhishekjacob21:
Hey guys,
I'm currently using the Adafruit CC3000 library to retrieve internet time and output it in the form of UNIX time. How do I now go about converting it to hh:mm:ss? I'm currently using Time.h with the following code:

unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000;

time_t currentTime = now();
Serial.print (hour());



This is returning the error "redeclaration of 'UINT32 currentTime'"
What am I doing wrong?
Thanks!

What you are doing wrong is posting a snippet instead of your entire sketch.

so currentTime outputs the unix time that needs to be converted.

NO! currentTime is a variable that can HOLD a value. If the value that it contains is some unix time, then the Time library has a function that can convert it to year, month, day, hour, minute, and second.