From owner-freebsd-questions@FreeBSD.ORG Wed Aug 11 08:44:42 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 24DDE16A4CE for ; Wed, 11 Aug 2004 08:44:42 +0000 (GMT) Received: from ux11.ltcm.net (ux11.ltcm.net [64.215.98.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6E03543D5E for ; Wed, 11 Aug 2004 08:44:41 +0000 (GMT) (envelope-from mipam@ibb.net) Received: from ux11.ltcm.net (mipam@localhost.ltcm.net [IPv6:::1]) by ux11.ltcm.net (8.12.9/8.12.9/UX11TT) with ESMTP id i7B8ibIo028988; Wed, 11 Aug 2004 10:44:37 +0200 (MEST) Received: from localhost (mipam@localhost) by ux11.ltcm.net (8.12.9/8.12.9/Submit) with ESMTP id i7B8iZmD006962; Wed, 11 Aug 2004 10:44:36 +0200 (MEST) X-Authentication-Warning: ux11.ltcm.net: mipam owned process doing -bs Date: Wed, 11 Aug 2004 10:44:34 +0200 (MEST) From: Mipam X-X-Sender: mipam@ux11.ltcm.net To: Giorgos Keramidas In-Reply-To: <20040810171119.GA26303@orion.daedalusnetworks.priv> Message-ID: References: <20040810162612 .GC25389@orion.daedalusnetworks.priv> <20040810171119.GA26303@orion.daedalusnetworks.priv> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-questions@freebsd.org Subject: Re: localtime question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2004 08:44:42 -0000 [SNIP] > You'd have to use strftime() and a local buffer for that. I found an example and adjusted it: #include #include int main() { struct tm *ptr; time_t tm; char str[60]; char str2[60]; char str3[60]; tm = time(NULL)-86400; ptr = localtime(&tm); strftime(str ,100 , "%d",ptr); strftime(str2 ,100 , "%m",ptr); strftime(str3 ,100 , "%Y",ptr); printf("%s %s %s\n",str3,str2,str); return 0; } This runs just fine: 2004 08 10 I dont know what the 100 is good for? I changed the first according your advice: #include #include #include int main(void) { struct timeval tv; struct timeval tv_current; if (gettimeofday(&tv_current, NULL) == -1) err(1, "Could not get local time of day"); tv.tv_sec = tv_current.tv_sec-86400; printf("%s", ctime((const time_t *) &tv.tv_sec)); /* printf("%s\n", ctime(&tv.tv_sec)); */ return 0; } Output: Tue Aug 10 10:42:26 2004 I compiled both with: cc -O3 -mcpu=pentiumpro -o time time.c Both compile without errors. Bye, Mipam.