From -1497750815259781663
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3b2d33f1a39395a6
X-Google-Attributes: gidf78e5,public
From: James Kuyper <kuyper@wizard.net>
Subject: Re: Getting system time
Date: 1999/03/15
Message-ID: <36EC0979.A3352AEF@wizard.net>#1/1
X-Deja-AN: 455095820
X-NNTP-Posting-Host: 209.8.153.20
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <Pine.SGI.3.96.990312091120.4086F-100000@aisa> <36E9A091.8E626706@technologist.com> <isvG2.191$TY3.231@news.get2net.dk>
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
X-Trace: news6.ispnews.com 921438432 209.8.153.20 (Sun, 14 Mar 1999 14:07:12 EDT)
Organization: Not Enough
Mime-Version: 1.0
NNTP-Posting-Date: Sun, 14 Mar 1999 14:07:12 EDT
Newsgroups: comp.std.c++
Originator: clamage@taumet


Lars Thorup wrote:
> 
> David R Tribble wrote in message <36E9A091.8E626706@technologist.com>...
> >Robert Batusek wrote:
> >> Is there any _portable_ (ANSI compatible) C++ possibility to get the
> >> system time?
> >> I have tried ftime but it doesn't work together with fstreams.
> >
> >Use time(), which is declared in <ctime> and <time.h>.  It's the
> >same as the standard C (C89) library function.  (ftime() is System
> >V Unix, and is deprecated.)
> 
> Be aware though, that the type time_t, which is the result type
> of the time() function, on many platforms cannot hold dates after the
> year 2038.

Presumably, that will get fixed some time before 2040 :-).

> So even though time() is portable between different platforms it is _not_
> portable between different decades... :-(

The solution to that problem, of course, is to convert the time returned
into a struct tm using gmtime(), and from there converting it into a
text string using asctime() or strftime() or time_put<>. In the reverse
direction, you can only use time_get<>, since neither asctime() nor
strftime() has a standardized inverse function.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




