ctime="+CCLK: "22/09/19,03:21:12+32""
void parsetime (const char *ctime)
{
char ptime[32]; //parse time
char *buf=(char *)malloc(sizeof(char) * 32);
struct tm tt;
time_t putime, \
nutime;
int time_zone=0;
sscanf(ctime, "%s %s", buf, ptime);
free(buf);
buf=strstr(ptime, "+");
if (buf == NULL)
buf=strstr(ptime, "-");
if (buf == NULL)
{
printf("err: can't find the time zone\n");
exit(1);
}
ptime[strlen(ptime)-strlen(buf)]='\0'; //remove time zone and late character
buf++; //get time zone
time_zone=atoi(buf);
buf=ptime+1; //remove first character
strncpy(ptime, buf, 32);
printf("time_zone=%d, buf=%s, ptime=%s\n", time_zone, buf, ptime);
strptime(ptime, "%y/%m/%d,%H:%M:%S", &tt);
tt.tm_hour+=(time_zone/4);
printf("tm_sec: %d\n",tt.tm_sec);
printf("tm_min: %d\n",tt.tm_min);
printf("tm_hour: %d\n",tt.tm_hour);
printf("tm_mday: %d\n",tt.tm_mday);
printf("tm_mon: %d\n",tt.tm_mon+1);
printf("tm_year: %d\n",tt.tm_year-100);
putime = mktime(&tt);
nutime=(long int)time(NULL);
printf("nutime-putime=%ld\n", nutime-putime);
return;
}
ref:
strptime
PLS83, RIL(libril-cwm-lte) network.c
void parseNITZresponse(char *szNITZrepsonse)
{
...
...
// All parameters available: generate NITZ notifications.
generateNITZnotification(nitzUtUCS2, nitzTZ, nitzDST);
}
other keywords:
RIL_UNSOL_NITZ_TIME_RECEIVED
Other keywords in Android:
frameworks/opt/telephony/src/java/com/android/internal/telephony/ServiceStateTracker.java
setTimeFromNITZString(nitzString, nitzReceiveTime)
ref:
1. android 手機的網絡時間同步
2. https://www.itdaan.com/tw/7a3b63850d9d
沒有留言:
張貼留言