int jam_sekarang() { int jam; time_t timeval; struct tm timeinfo; get_tm_time( &timeinfo ); return timeinfo.tm_hour; //printf("skrg: %d\r\n", jam); //return jam; }
// opsi 1: jam // opsi 2: tgl // opsi 3: bulan // opsi 4: tahun // return: count int cek_waktu(int *waktu, int opsi) { time_t timeval; struct tm timeinfo; get_tm_time( &timeinfo ); timeval = mktime( &timeinfo ); int count=0, flag; int tglnya_1; int tmp, tmpx; if (opsi<0 || opsi>4) { return -1; } //printf("_____________________awal: %d\r\n", *waktu); if (opsi==1) { // jam tmp = timeinfo.tm_hour; // tmp = 13 tmp -= *waktu; // tmp = 13-13 while(tmp<0) { // tmp = 13-55 tmp += 24; count++; } *waktu = tmp; return count; } else if(opsi==2) { // tgl tmp = timeinfo.tm_mday; // tmp = 1 tmpx = timeinfo.tm_mon; // tmpx= 1 tmp -= *waktu; // tmp = 1-1=0 while(tmp<1) { if (cek_kabisat(timeinfo.tm_year+1900)) { // tahun kabisat tglnya_1 = (int)kabisat[tmpx-count-1];// [1-0-1] = 0 : januari } else { tglnya_1 = (int)tgl[tmpx-count-1]; } if(tmp<1) { count++; // count = 1 tmp += tglnya_1; // tmp = 0+31 // jika lintas tahun // if (count>=tmpx) { // 1, 1 tmpx=count+12; } } } *waktu = tmp; return count; } else if (opsi==3) { tmp = timeinfo.tm_mon; tmpx = tmp-*waktu; tmp-=*waktu; while (tmp<0) { // bulan bisa = 0 karena array. bulan[0] = januari. tmp += 12; count++; // 1 th sebelumnya } *waktu = tmp; return count; } else if (opsi==4) { tmp = timeinfo.tm_year+1900; tmp-=*waktu; *waktu = tmp; return count; } }
void cari_waktu(char *dest, char *posisi) { if ((posisi[0]!='H') && (posisi[0]!='h') && (posisi[0]!='J') && (posisi[0]!='j') && (posisi[0]!='B') && (posisi[0]!='b') ) { printf("Argumen tidak benar !!\r\n"); printf("Contoh : H-7, J-2, B-1\r\n"); sprintf(dest,"\\"); return; } struct t_simpan_file *p_gr; p_gr = (char *) ALMT_SFILE; time_t timeval; struct tm timeinfo; get_tm_time( &timeinfo ); timeval = mktime( &timeinfo ); char *pch, str[10]; int tmp, tmpx; int ijam, itgl, ibulan, ithn, count; //printf("%s sekarang: %d:%d %d-%d[%s]-%d\r\n", posisi, timeinfo.tm_hour, timeinfo.tm_min, \ // timeinfo.tm_mday, timeinfo.tm_mon+1, bulan[timeinfo.tm_mon], timeinfo.tm_year+1900); pch=strstr(posisi,"-"); if (pch!=NULL) strcpy(str, pch+1); else return 0; itgl = timeinfo.tm_mday; ibulan = timeinfo.tm_mon; ithn = timeinfo.tm_year+1900; if ( (posisi[0]=='H') || (posisi[0]=='h') ) { tmp = atoi(str); count = cek_waktu(&tmp, 2); itgl = tmp; tmp = count; if (count>0) { count = cek_waktu(&tmp, 3); ibulan = tmp; } tmp = count; if (count>0) { count = cek_waktu(&tmp, 4); ithn = tmp; } sprintf(dest,"\\%s\\tahun_%d\\%s\\tgl_%d", p_gr->direktori, ithn, bulan[ibulan], itgl); } else if ( (posisi[0]=='J') || (posisi[0]=='j') ) { tmp = atoi(str); count = cek_waktu(&tmp, 1); // x tgl sebelumnya, count = 2 ijam = tmp; tmp = count; if (count>0) { count = cek_waktu(&tmp, 2); itgl = tmp; } tmp = count; if (count>0) { count = cek_waktu(&tmp, 3); ibulan = tmp; } tmp = count; if (count>0) { count = cek_waktu(&tmp, 4); ithn = tmp; } sprintf(dest,"\\%s\\tahun_%d\\%s\\tgl_%d\\jam_%02d", p_gr->direktori, ithn, bulan[ibulan], itgl, ijam); } else if ( (posisi[0]=='B') || (posisi[0]=='b') ) { printf("%d Bulan sebelumnya: %d\r\n", atoi(str), timeinfo.tm_mon+1-atoi(str)); } else { printf("Input salah\r\n"); } }
static void fill_systime(mame_system_time *systime, time_t t) { systime->time = t; get_tm_time(localtime(&t), &systime->local_time); get_tm_time(gmtime(&t), &systime->utc_time); }
int jam_sekarang() { time_t timeval; struct tm timeinfo; get_tm_time( &timeinfo ); return timeinfo.tm_hour; }