Take date/time data from SIM900 RTC (string)


I want to extract date/time data from SIM 900 RTC as a string.

I use this code

#include "SIM900.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
int i=0;

#define CCLK_MSG_LEN 28  // total characters in the CCLK message
#define TIME_STR_LEN 18  // the actual number of characters for date and time

char timeStr[TIME_STR_LEN]; // holds the time string
char timePreamble[] = "CCLK: \"" ; // there is a quotation mark in the string so we need the C escape char

void setup(){
  //lcd.begin(16, 2);  
 Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  mySerial.println( "AT+CLTS=1");
 mySerial.println( "AT+CCLK =\"15/07/3,17:15:00+28\"");
boolean getTime(){
  // Check for available bytes
 if(mySerial.available() < CCLK_MSG_LEN )
    return false;  // Not enough characters for a full message.  Try again later

   if(mySerial.read() != '+')
     return false;  // Not in sync yet

     // In sync.  Check the preamble
     for(int i=0; i < strlen(timePreamble); i++) {
       if(mySerial.read() != timePreamble[i] )
         return false; // exit if the received data does not match the preamble 

     // Preamble checked.  We are now at the start of the time data
     for(int i=0; i < TIME_STR_LEN; i++)
       timeStr[i] = mySerial.read();
     return true; // we have filled the timeString with valid data 

// converts two characters from date string into a two digit decimal value
int dateToDecimal(char * date){
 int value = ((date[0] - '0') * 10) +  (date[1] - '0');
 return value;

void loop()
 int years, months, dates, hours, minutes, seconds;
 mySerial.println( "AT+CCLK?" );
 if(getTime() == true){
   years    = dateToDecimal(&timeStr[0]) ;
   months   = dateToDecimal(&timeStr[3]) ;
   dates    = dateToDecimal(&timeStr[6]) ;
   hours    = dateToDecimal(&timeStr[9]) ;
   minutes  = dateToDecimal(&timeStr[12]) ;
   seconds  = dateToDecimal(&timeStr[15]) ;}

Serial.println("There is something wrong");

   Serial.println("date components are ");
   Serial.print("Year: ");
   Serial.print("Month: ");
   Serial.print("Date: ");
   Serial.print("Hour: ");
   Serial.print("Minute: ");

But the result shown in serial monitor is unknown sequence of number

There is something wrong
date components are
Year: 512
Month: 3934
Date: 4357
Hour: 393
Minute: -2185

I noticed that "There is something wrong" was also printed, therefore maybe getTime() returning false value, but i dont know why

Any idea how to fix this and get the right date/time data?