Syncing Arduino time from a string

Hi I wonder if anyone can help. I am pretty new to arduino.
i have the SIM900 GPRS shield and have that working fine. I now want to use the RTC on the board. I can get the time from the board in a string that looks like this…

But I just dont know how to set the arduino time by this string. Is it even possible?

This is the bit that gets the time from the SIM900 and puts it in a string.

 String mystr="";
  int i = 0;
  delay (500);
  while (mySerial.available()>0) {
    mystr += char(;
  Serial.println("My String |"+mystr+"|");
  String clockString = "";
  int x = mystr.indexOf(String('"'))+1;   // Find the first occurance of an open quotation.  This is where we begin to read from
  int y = mystr.lastIndexOf(String('"')); // Find the last occurance of an open quotation. This is where we end.
  Serial.println(mystr.substring(x,y));   // This is the time string yy/mm/dd,hh:mm:ss-tz (tz in qtrs)

//time1 = (mystr.substring(x,y));
  while (<1); // Sit and do nothing

What do mean by Arduino time?

The basic Arduino does not have a RTC on the board - you can add a RTC shield etc. or you could implement a clock in the Arduino and set it from the string as you seem to be implying, but there is not "Arduino time" without adding a time library etc. to your code. As far as the string from the GPRS goes, yes, you can parse any string that contains the data you want in some format to whatever format you need.

Yes, sorry I have the time library included at the start and I just want to set that time with the string :slight_smile:

Maybe a link to the SIM900 board will help. A little digging with google did not reveal a SIM900 board with a RTC.

Or you have a non-standard Arduino that has a RTC on board? Which RTC chip?

Which time library are you using; link please.

Thanks for getting back to me. The gprs shield I have is this one...

It has its own clock that can sync with a time server using AT commands. I've done that, no problem.
To get the time from the module you have to send AT comand "AT+CCLK?" which returns...
+CCLK: "24/04/16,21:29:08+01"

I can then get that to just the time and date but I just dont know how to parse that into setTime();
I am using the time library from here...



Since you have a nice delimited stream...

Save the return as a null terminated char array (so-called C string) instead of a String class object Then use strtok() to parse it into its elements.

Then, construct a time_t object and update Time.