How to synchronize RTC with PC when i burn the sketch

Hi all!
I’m using two DS3232 RTC with two Arduino boards. But i want to synchronize both of RTC.
So what i think is sync the PC time everytime when i burn the sketch.
Here’s the code of I’m using now. Always need to set by myself, so it won’t be accurate.

void setup() {
    Serial.begin( 9600 );
 
    while( !Serial ){;}
    xbeeSerial.begin( 9600 );
    xbee.setSerial( xbeeSerial );
  /*setTime(14, 56, 59, 13, 2, 2017);    //set the time at first time and then annotation it
    RTC.set(now());*/
    
    setSyncProvider(RTC.get);
    Serial << "RTC Sync";
    if (timeStatus() != timeSet){
        Serial << " FAIL!";
    }
    Serial << endl;

    printDateTime( RTC.get() );
    Serial << " --> Current RTC time." << endl;

    //Disable the default square wave of the SQW pin.
    RTC.squareWave(SQWAVE_NONE);

    //Attach an interrupt on the falling of the SQW pin.
    //digitalWrite(SQW_PIN, HIGH);    //redundant with the following line
    pinMode(SQW_PIN, INPUT_PULLUP);
    attachInterrupt(INT0, alarmIsr, CHANGE);

    //Set an alarm at every 20th second of every minute.
    RTC.setAlarm(ALM1_MATCH_SECONDS, 30, 0, 0, 1);    //daydate parameter should be between 1 and 7
    RTC.alarm(ALARM_1);                   //ensure RTC interrupt flag is cleared
    RTC.alarmInterrupt(ALARM_1, true);

    //Set an alarm every minute.
    RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 1);    //daydate parameter should be between 1 and 7
    RTC.alarm(ALARM_2);                   //ensure RTC interrupt flag is cleared
    RTC.alarmInterrupt(ALARM_2, true); 
}

You have the predefined standard preprocessor macros DATE and TIME. But you have to take apart these strings yourself.

Also keep in mind that the IDE uses several seconds from the compilation until the sketch gets started. Also every time your reset your Arduino the time will be reset to that compiled in constant.

Hello pylon!
I found this way could synchronize my RTC with computer.
Now it work greatly except a little problem.
What I'm doing is use DS3232 make the sleeping Arduino wake up every 30 minutes.
After wake up, it will send the data through Xbee router to Xbee coordinator.
The problem is as time increase, the time will have error quantity about 1 second every around 7 hours.

02-14-2017 08:39:09.732,-,API2," ,0013A20040D8DA8D,ZigBee Coordinator API,21A7,COM6 - 9600/8/N/1/N,0"

02-13-2017 22:55:00.599,0,RECV,7E0014900013A20040D8DA68BF340134372E3632352E30D8
02-13-2017 22:55:30.599,1,RECV,7E0014900013A20040D8DA68BF340134352E3932352E30D7
02-13-2017 22:56:00.599,2,RECV,7E0014900013A20040D8DA68BF340134352E3232342E39D6
02-13-2017 22:56:30.599,3,RECV,7E0014900013A20040D8DA68BF340134352E3032342E39D8
02-13-2017 22:57:00.609,4,RECV,7E0014900013A20040D8DA68BF340134352E3032342E39D8
02-13-2017 22:57:30.619,5,RECV,7E0014900013A20040D8DA68BF340134342E3932342E38D1
02-13-2017 22:58:00.619,6,RECV,7E0014900013A20040D8DA68BF340134352E3232342E38D7
02-13-2017 22:58:30.610,7,RECV,7E0014900013A20040D8DA68BF340134352E3332342E38D6


02-14-2017 06:46:31.013,943,RECV,7E0014900013A20040D8DA68BF340134362E3532322E39D4
02-14-2017 06:47:01.007,944,RECV,7E0014900013A20040D8DA68BF340134362E3532322E39D4
02-14-2017 06:47:31.011,945,RECV,7E0014900013A20040D8DA68BF340134362E3532322E39D4
02-14-2017 06:48:00.984,946,RECV,7E0014900013A20040D8DA68BF340134362E3532322E39D4

I'll keep working on it, thanks you!

The datasheet of the DS3232 tells an accuracy of 2ppm in standard conditions, resulting in a max. error of 1 second in about 6 days. How do you get to 1 second in 7 hours? You should get a higher accuracy with a DS1307.

I don't understand what your problem is actually.