From owner-freebsd-questions@FreeBSD.ORG Tue Aug 10 17:11:25 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 9F17416A4CE for ; Tue, 10 Aug 2004 17:11:25 +0000 (GMT) Received: from rosebud.otenet.gr (rosebud.otenet.gr [195.170.0.26]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9FA0A43D45 for ; Tue, 10 Aug 2004 17:11:24 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226])i7AHBL5e021026; Tue, 10 Aug 2004 20:11:22 +0300 Received: from orion.daedalusnetworks.priv (orion [127.0.0.1]) i7AHBJHQ026461; Tue, 10 Aug 2004 20:11:19 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost)i7AHBJin026460; Tue, 10 Aug 2004 20:11:19 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Tue, 10 Aug 2004 20:11:19 +0300 From: Giorgos Keramidas To: Mipam Message-ID: <20040810171119.GA26303@orion.daedalusnetworks.priv> References: <20040810162612.GC25389@orion.daedalusnetworks.priv> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: Tue, 10 Aug 2004 17:11:25 -0000 On 2004-08-10 18:45, Mipam wrote: > > Try calling ctime() with the address of tv.tv_sec: > > > > printf("%s\n", ctime(&tv.tv_sec)); > > #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\n", ctime(&tv.tv_sec)); > return 0; > } > > Does the job, thanks! > At compile time i get: > > tijd.c: In function `main': > tijd.c:11: warning: passing arg 1 of `ctime' from incompatible pointer type That's because struct timeval's members are `long' not time_t. printf("%s\n", ctime((const time_t *) &tv.tv_sec)); Add to your includes too and sort them in this order: #include #include #include System headers first, the rest afterwards; each list sorted alphabetically unless there is a good reason to do otherwise. This becomes handy when there are long lists of headers as it's easy to spot and fix duplicate includes :-) > Only thing left is another format like: 2004 Aug 9 18:44:04 > Any hints? You'd have to use strftime() and a local buffer for that. Cheers