Article View: borland.public.cppbuilder.nativeapi
Article #4933Re: time_t to TDateTime
From: Steve Aletto
Date: Wed, 12 Oct 2005 14:44
Date: Wed, 12 Oct 2005 14:44
24 lines
1546 bytes
1546 bytes
> How do I convert a time_t to a TDateTime? I try
> TDateTime::FileTimeToDateTime() but it fails.
One way:
TDateTime timet2datetime(const time_t t)
{
TDateTime rv;
struct tm *stm = localtime(&t);
if (stm)
{
rv = TDateTime(stm->tm_year + 1900, stm->tm_mon + 1,
stm->tm_mday);
rv += TDateTime(stm->tm_hour, stm->tm_min, stm->tm_sec,
0);
}
return(rv);
}
I think this is not thread-safe. Furthermore, it introduces a
memory leak due to localtime(), but I don't know whether it can
be solved.
Steve.
Technical Details
Message-ID:
<434d20f1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<434cfde3$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,abdfe71df549986f X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Steve Aletto" <stevealettoANTI@SPAMgmail.com> From: "Steve Aletto" <stevealettoANTI@SPAMgmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <434cfde3$1@newsgroups.borland.com> Subject: Re: time_t to TDateTime Date: Wed, 12 Oct 2005 16:44:55 +0200 Lines: 26 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 81.208.124.114 Message-ID: <434d20f1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1129128177 81.208.124.114 (12 Oct 2005 07:42:57 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail