Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
date diff sample
#include <stdio.h> #include <time.h> #include <stdlib.h> #define DEBUG //COMMENTARE LA RIGA PER TOGLIERE STAMPE DEBUG /* per debug print #ifdef DEBUG printf(""); #endif */ void printdate(time_t t){ /* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz" */ struct tm *ts; char buf [80]; ts = localtime(&t); strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts); puts(buf); } int main (void) { /// AREA INIZIALIZZAZIONI struct tm data1; struct tm data2; struct tm *dt1, *dt2; time_t d1,d2; int d, m, y; //AREA CODICE //prima cosa, con time ci si prende l'ora corrente (passando null come parametro) d1=time(NULL); d2=time(NULL); // local time converte un time_t in *tm dt1=localtime(&d1); dt2=localtime(&d2); //adesso convertiamo così *tm in un tm data1=(*dt1); data2=(*dt2); //IL RESTO DEL PROGRAMMA È RIMASTO UGUALE, HO SOLO DIVISO LE OPERAZIONI PER MAGGIORE EVIDENZA //INIZIA L'INPUT DA TASTIERA, SEGUIRANNO DELLE STAMPE DI DEBUG. printf("prima data \n"); d=1;m=1;y=1991; #ifdef DEBUG printf("Data inserita: %d/%d/%d\n",d,m,y); #endif data1.tm_mday = d; //Range [1-31] data1.tm_mon = m - 1; //Range [0-11] data1.tm_year = y - 1900; //Range >= 1900 #ifdef DEBUG printf("Data trascritta in tm: %d/%d/%d\n",data1.tm_mday,data1.tm_mon,data1.tm_year); #endif printf("seconda data \n"); d=1;m=2;y=1991; #ifdef DEBUG printf("Data inserita: %d/%d/%d\n",d,m,y); #endif data2.tm_mday = d; data2.tm_mon = m - 1; data2.tm_year = y - 1900; #ifdef DEBUG printf("Data trascritta in tm: %d/%d/%d\n",data2.tm_mday,data2.tm_mon,data2.tm_year); #endif d1=mktime(&data1); #ifdef DEBUG printf("\ntempo 1:\n"); printdate(d1); #endif d2=mktime(&data2); #ifdef DEBUG printf("\ntempo 2:\n"); printdate(d2); #endif double differenza=difftime(d1, d2); #ifdef DEBUG printf("\nla differenza in secondi è %lf:\n",differenza); #endif double diff=abs(differenza/86400); printf("La differenza tra le due date e' di %lf giorni\n", diff); }
run
|
edit
|
history
|
help
1
B_141121_factorial01
a>=0 && b>=a
Example array of struct print
summing long int
20171116_TARTAGLIA
Vowel Assignment
GCC supports 128-bit integer arithmetic
Star1..3
Practica 5 ejercicio beneficio empresa
Lab6 v1.2 Sin,cos,tan,cot